none
How to get the Lat/Long clicking on polyline RRS feed

  • Question

  • Hi,

    While clicking on Polyline am not able to get the Lat/Long (point) . Can any one please help me out, how to get it.

    I am pasting the code here.

    if (e.targetType == "polyline") {var point1 = new Microsoft.Maps.Point(e.getX(), e.getY());

    var loc = e.target.tryPixelToLocation(point1);

    var latTest = loc.latitude;

    var longTest = loc.longitude;

    alert(

    "Lattitude is" + latTest + "" + longTest);

    }

    Tuesday, October 8, 2013 2:10 PM

Answers

  • If I understand correctly you want to be able to select a point on a polyline. If you just want to select existing points on the polyline then you can do a simple search for the closest coordinate to where the user clicked. If you wanted to get the exact location a user clicked on between data points on the polyline, then this may be a bit more difficult. The easiest solution would be to use thetryPixelToLocation method on the map and not the e.target. This will give you a location that is very close to being on the line but may not be 100% centimetre accuracy. The accurate method would be to calculate the closest intersection point on the line. This would involve some in depth spherical mathematics.

    http://rbrundritt.wordpress.com

    Wednesday, October 9, 2013 10:59 AM

All replies

  • where clicked on polyline need to get the point(Lat/Long). Below code not able to get the point.

    var loc = e.target.tryPixelToLocation(point1);

    Any other code to get the Lat/Long.

    Wednesday, October 9, 2013 7:31 AM
  • If I understand correctly you want to be able to select a point on a polyline. If you just want to select existing points on the polyline then you can do a simple search for the closest coordinate to where the user clicked. If you wanted to get the exact location a user clicked on between data points on the polyline, then this may be a bit more difficult. The easiest solution would be to use thetryPixelToLocation method on the map and not the e.target. This will give you a location that is very close to being on the line but may not be 100% centimetre accuracy. The accurate method would be to calculate the closest intersection point on the line. This would involve some in depth spherical mathematics.

    http://rbrundritt.wordpress.com

    Wednesday, October 9, 2013 10:59 AM