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 Saturday, March 10, 2012 10:50 AM (From:Bing Maps: Map Control and Web services Development)
Saturday, October 2, 2010 11:42 PM

• 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
Sunday, October 3, 2010 5:58 PM
• 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=ceb4346f-657f-4d28-83f5-aae0c5c83d52&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
Sunday, October 3, 2010 7:05 PM

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
Sunday, October 3, 2010 5:58 PM
• 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=ceb4346f-657f-4d28-83f5-aae0c5c83d52&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
Sunday, October 3, 2010 7:05 PM
• Thank you very much
Wednesday, October 6, 2010 8:44 AM
• How can I get the disatance between two point in javascript?

Friday, September 9, 2011 8:37 AM
• As Ricky already said, use the Haversine formula.