How to get lat/lon of a mouse click with Bing Maps AJAX Control v7

前端 未结 1 533
执笔经年
执笔经年 2021-02-14 04:30

I am using th newest version of the API (v7), and would like to add a pushpin on mouse-click ...

var mapSettings = {
    \'credentials\': \'myCredentials\',
             


        
相关标签:
1条回答
  • 2021-02-14 05:25

    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() only works when the target is a pushpin, infobox, etc. The click on the actual map is different.

    0 讨论(0)
提交回复
热议问题