Sometime while working with map control in Windows Phone, we may need to calculate distance between two GeoCoordinates. The Windows Phone 8 SDK already provides you the required API for you to calculate the distance very easily.
If you are looking for a piece of code to do the same, here is the small post for you to understand the API and the way to use it in your app.
We are already aware of the class “System.Device.Location.GeoCoordinate” present under the “System.Device.dll”. The class GeoCoordinate provides a method named “GetDistanceTo(…)” which takes a parameter of type GeoCoordinate and returns the distance between the two in meters.
If you want to know, how to retrieve the GeoCoordinate/GeoLocation in Windows Phone 8, check out this in-depth post for details: “How to get Geolocation in Windows Phone 8?”
Here the below code snippet shows you how to calculate the distance between two GeoCoordinates named “newCoordinate” and “previousCoordinate”:
var distance = newCoordinate.GetDistanceTo(previousCoordinate);
Once it executes the API call, will return you the distance in meter between the current GeoCoordinate (newCoordinate) and provided GeoCoordinate (previousCoordinate).
I hope this small post will help you to find the distance between two coordinate points in your Windows Phone 8 application. Check out my other Windows Phone 8 articles for more details. I am available on Twitter, Facebook and Google+. Get in touch with me for any queries or technical updates. Cheers.