Calculate distance between two points in bing maps

bing-maps, c#-4.0, silverlight-4.0

Solution

See Haversine or even better the Vincenty formula how to solve this problem.

The following code uses haversines way to get the distance:

public double GetDistanceBetweenPoints(double lat1, double long1, double lat2, double long2)
    {
        double distance = 0;

        double dLat = (lat2 - lat1) / 180* Math.PI;
        double dLong = (long2 - long1) / 180 * Math.PI;

        double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2)
                    + Math.Cos(lat1 / 180* Math.PI) * Math.Cos(lat2 / 180* Math.PI) 
                    * Math.Sin(dLong/2) * Math.Sin(dLong/2);
        double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));

        //Calculate radius of earth
        // For this you can assume any of the two points.
        double radiusE = 6378135; // Equatorial radius, in metres
        double radiusP = 6356750; // Polar Radius

        //Numerator part of function
        double nr = Math.Pow(radiusE * radiusP * Math.Cos(lat1 / 180 * Math.PI), 2);
        //Denominator part of the function
        double dr = Math.Pow(radiusE * Math.Cos(lat1 / 180 * Math.PI), 2)
                        + Math.Pow(radiusP * Math.Sin(lat1 / 180 * Math.PI), 2);
        double radius = Math.Sqrt(nr / dr);

        //Calculate distance in meters.
        distance = radius * c;
        return distance; // distance in meters
    }

You can find a good site with infos here.

Problem

Ihave a bing map, and a two points : Point1,Point2 and i want to calculate the distance between these two points? is that possible? and if i want to put a circle on the two third of the path between point1 and point2 and near point2 ...how can i make it?

Original source