Answered by:
Distance between two points
Question

Hi!
Is there a way for calculate the route distance (the distance that the car have to drive) between two points that are on the same route?
I call the Route Service that give me back the points collection the compose the route,
Is there a way to calculate the distance that the car have to drive between two points that I choose from the route?
Thanks
 Moved by Ricky_Brundritt Saturday, March 10, 2012 10:50 AM (From:Bing Maps: Map Control and Web services Development)
Answers

By default the total length of the route is returned with the route request. If you want to calculate the distance between two points along that route you can do a quick search to find the closest coordinates on the route and then loop through the points in between and calculate the sum of the distances between each coordinate. To calculate the straight line distance between two coordinates use the Haversine formula: http://rbrundritt.spaces.live.com/blog/cns!E7DBA9A4BFD458C5!317.entry
Windows Live Developer MVP  http://rbrundritt.spaces.live.com  http://inknowledge.co.uk Marked as answer by Gabriele Guerra Wednesday, October 6, 2010 8:43 AM

If you're using .NET, you can import the SqlServer.Types.dll library that comes with the SQL Server 2008 redistributable feature pack (http://www.microsoft.com/downloads/en/details.aspx?FamilyID=ceb4346f657f4d2883f5aae0c5c83d52&displaylang=en)
That will let you use exactly the same spatial methods as you can in SQL Server 2008, including using methods such as STDistance() to calculate the distance between a set of points.
Beginning Spatial with SQL Server http://www.apress.com/book/view/1430218290 Marked as answer by Gabriele Guerra Wednesday, October 6, 2010 8:43 AM
All replies

By default the total length of the route is returned with the route request. If you want to calculate the distance between two points along that route you can do a quick search to find the closest coordinates on the route and then loop through the points in between and calculate the sum of the distances between each coordinate. To calculate the straight line distance between two coordinates use the Haversine formula: http://rbrundritt.spaces.live.com/blog/cns!E7DBA9A4BFD458C5!317.entry
Windows Live Developer MVP  http://rbrundritt.spaces.live.com  http://inknowledge.co.uk Marked as answer by Gabriele Guerra Wednesday, October 6, 2010 8:43 AM

If you're using .NET, you can import the SqlServer.Types.dll library that comes with the SQL Server 2008 redistributable feature pack (http://www.microsoft.com/downloads/en/details.aspx?FamilyID=ceb4346f657f4d2883f5aae0c5c83d52&displaylang=en)
That will let you use exactly the same spatial methods as you can in SQL Server 2008, including using methods such as STDistance() to calculate the distance between a set of points.
Beginning Spatial with SQL Server http://www.apress.com/book/view/1430218290 Marked as answer by Gabriele Guerra Wednesday, October 6, 2010 8:43 AM



As Ricky already said, use the Haversine formula.
twitter: @alastaira blog: http://alastaira.wordpress.com/