如何使用Bing Maps AJAX Control v7来获得鼠标的经纬度 [英] How to get lat/lon of a mouse click with Bing Maps AJAX Control v7
本文介绍了如何使用Bing Maps AJAX Control v7来获得鼠标的经纬度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用最新版本的API(v7),并希望在鼠标单击时添加图钉...
I am using th newest version of the API (v7), and would like to add a pushpin on mouse-click ...
var mapSettings = {
'credentials': 'myCredentials',
'mapTypeId': Microsoft.Maps.MapTypeId.road,
'enableSearchLogo': false,
'showMapTypeSelector': false,
'showScalebar': false
};
var $map = $('#map');
var map = new Microsoft.Maps.Map($map.get(0), mapSettings);
Microsoft.Maps.Events.addHandler(map, 'click', function (e) {
var latitude = ?
var longitude = ?
var location = new Microsoft.Maps.Location(latitude, longitude);
var pushpin = new Microsoft.Maps.Pushpin(location, {
'draggable': true
});
map.entites.push(pushpin);
});
如您所见,我陷入了点击处理程序中:如何获得纬度&点击的经度?
As you see, I am stuck within the click-handler: How do I get latitude & longitude of the click?
推荐答案
好的,钉上了它.这是您感兴趣的一些代码:
Ok, nailed it. Here's the bit of code that you're interested in:
if (e.targetType == "map") {
var point = new Microsoft.Maps.Point(e.getX(), e.getY());
var loc = e.target.tryPixelToLocation(point);
var location = new Microsoft.Maps.Location(loc.latitude, loc.longitude);
......
}
e.target.getLocation()
仅在目标是图钉,信息框等时才起作用.实际地图上的单击是不同的.
e.target.getLocation()
only works when the target is a pushpin, infobox, etc. The click on the actual map is different.
这篇关于如何使用Bing Maps AJAX Control v7来获得鼠标的经纬度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文