Answered by:
How to get the Lat/Long clicking on polyline
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);}
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
 Marked as answer by Ricky_Brundritt Wednesday, October 30, 2013 9:45 AM
All replies


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
 Marked as answer by Ricky_Brundritt Wednesday, October 30, 2013 9:45 AM