1
votes

Im developing an webapplication using Bing Maps V7.0 I've created a fully functional context menu, but now i want to implement it using driving directions and then i need to get the lat lon of the cursor when it's right clicked and the menu are brought up. This is how you create it in an old Bing Maps version. But it doesn't work anymore.

e.view.LatLong.Latitude

So if anyone know the new method for finding the cursor location when clicked please tell me.

1

1 Answers

3
votes

It's changed to:

e.target
    .tryPixelToLocation(new Microsoft.Maps.Point(e.getX(), e.getY()))
    .latitude

I found the code on the MouseEventArgs documentation page:

map = new Microsoft.Maps.Map(
    document.getElementById("myMap"),
    {credentials:"Bing Maps Key"}
);
Microsoft.Maps.Events.addHandler(map, 'click', displayEventInfo);

// ...

function displayEventInfo(e) {
    if (e.targetType == "map") {
        var point = new Microsoft.Maps.Point(e.getX(), e.getY());
        var loc = e.target.tryPixelToLocation(point);
        document.getElementById("textBox").value = loc.latitude
            + ", " + loc.longitude;
    }
}