How to calculate distance between two coordinates in WindowsPhone?


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.


If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on Twitter , Facebook , Google+ and LinkedIn . I would love to hear your thoughts and opinions on my articles directly. Also, don't forget to share your views and/or feedback in the comment section below.

0 comments


 
© 2008-2016 Kunal-Chowdhury.com - Microsoft Technology Blog for developers and consumers | Designed by Kunal Chowdhury
Back to top