但是翻遍官方说明文档,并没有展示如何获得事件的经纬度。网上查询好久,均未找到。摸索许久,终于获知。在此粘出,方便他人,亦供自己日后查阅。html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Map with valid credentialsvar map = null;
function getMap()
{
map = new Microsoft.Maps.Map(document.getElementById('myMap'), {
credentials: 'your credentials', zoom: 3});//这里修改为你的密码
Microsoft.Maps.Events.addHandler(map, 'click', displayInfo);
}
function displayInfo(e){
//若点击到地图的标记上,而非地图上
var loc;
if (e.targetType == "pushpin") {
loc = e.target.getLocation();
}
//若点击到地图上
else {
var point = new Microsoft.Maps.Point(e.pageX, e.pageY);
loc = e.target.tryPixelToLocation(point, Microsoft.Maps.PixelReference.page);
}
alert(loc.latitude+", "+loc.longitude);
}
如上代码,可知获得点击地点的经纬度还比较麻烦,得分情况讨论。下面是效果图: