Friday, March 22, 2013

Calculating Distance with Google API and C#

Recently I had to use C# to calculate driving mileage between two locations.  Here's a great resource I found but they calculate in metric.

http://briancray.com/posts/calculate-driving-distance-google-maps-api

To convert the distance into miles, make the following modification at the end:


                miles = Math.Round((Double.Parse(distanceNode[0].ChildNodes[0].InnerText) / 1609.344d) * 100) / 100;

That's it! Very useful!

No comments:

Post a Comment