Finding distances

Hey, Could someone point me to documentation on how to find distance between to locations via their lat/long or another way to do what i'm trying to do


I have a list of locations and their latitude/longitude and I want to display a map that zooms out to display a minimum of 10 locations near a location that is typed in.




Answer this question

Finding distances

  • incendy

    Ok it is a little complex becouse the world is not flat (shock!) its a sphere (sort of).

    If you don't care about accuracy and the points are within a few hundred miles then you can go with simple trig.

    square root of ((Lat2-lat1)squared + (Long2-Long1)squared)

    type thing. But if you want accuracy you should read this:

    http://www.movable-type.co.uk/scripts/LatLong.html

    John.



  • mahima

    There isn't a way to just generate a range of lat/long for a 10 mile surrounding area or something like that


  • Shady9399

    I needed this exact same thing and have posted the code to the Code Wiki.

    Get it here: http://viavirtualearth.com/Wiki/distance.ashx


  • ACHawk

    Since Mappoint Web Service is tied in with Virtual Earth, I'll mention you can do this easily by calculating a route and then checking the distance between the two lat longs. If you do it this way then you'll need to look over previous posts on how to integrate your results from MWS into Virtual Earth

  • vbnvbn

    double lat = 40.657498;

    double lng = -111.865899;

    int DiameterEarth = 25000;

    double degreeOfLatitude = DiameterEarth / 360;

    double oneMileDegree = (1 / degreeOfLatitude) * 10;

    double degreeOfLongitude = degreeOfLatitude * Math.Cos(lat * (180 / Math.PI));

    double oneMileDegreeLng = (1 / degreeOfLongitude) * 10;

    Console.WriteLine("Lat Range: {0}:{1}", lat - oneMileDegree, lat + oneMileDegree);

    Console.WriteLine("Long Range: {0}:{1}", lng - oneMileDegreeLng, lng + oneMileDegreeLng);

    Console.ReadLine();



  • Nimrand

    Yeah thats the best one JonnyAJAX, that's the site where i got the more accurate circles from.

    I'm thinking maybe we need to wrap a few of these up into a helper class specifically for VE.

    Thanks for putting it on the WIKI.

    John.



  • Monte Chan

    you could also try to use the map getRoute method (passing as parameters both lats and longs) and then in the callback you can know how far away are both points.

    regards

    dario


  • Finding distances