Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET
Hi,
I am developing a Windows 8 App. I have a requirement to find the shortest distance between two locations by road using bing maps. How to do that?
 
Thanks,
Kalai
Posted 11-Oct-12 0:00am
kalai91201

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi Kalai91
 
try this to calculate distance b/w tow places in window 8 App
 
private double CalculateDistance(double prevLat, double prevLong, double currLat, double currLong)
       {
           const double degreesToRadians = (Math.PI / 180.0);
           const double earthRadius = 6371; // kilometers

           // convert latitude and longitude values to radians
           var prevRadLat = prevLat * degreesToRadians;
           var prevRadLong = prevLong * degreesToRadians;
           var currRadLat = currLat * degreesToRadians;
           var currRadLong = currLong * degreesToRadians;
 
           // calculate radian delta between each position.
           var radDeltaLat = currRadLat - prevRadLat;
           var radDeltaLong = currRadLong - prevRadLong;
 
           // calculate distance
           var expr1 = (Math.Sin(radDeltaLat / 2.0) *
                        Math.Sin(radDeltaLat / 2.0)) +
 
                       (Math.Cos(prevRadLat) *
                        Math.Cos(currRadLat) *
                        Math.Sin(radDeltaLong / 2.0) *
                        Math.Sin(radDeltaLong / 2.0));
 
           var expr2 = 2.0 * Math.Atan2(Math.Sqrt(expr1),
                                        Math.Sqrt(1 - expr1));
 
           var distance = (earthRadius * expr2);
           return distance * 1000;  // return results as meters
       }
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 26 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100