views:

242

answers:

2

Hi There,

I'm looking to develop/obtain a simple GMaps app for my site that lets the user plot two points and get the distance between the two.

Here is an app that would be perfect for me. http://www.daftlogic.com/projects-google-maps-distance-calculator.htm

I suppose "as the crow flies" could suffice but "suggested route" measurements would be great if possible and too time consuming.

Does anybody know if there is something like this available for download? Also, would it be difficult/time consuming to dev this from scratch?

unfortunately it's only a small piece of a much larger projecet so I won't be able to spend too much time on it.

Any advice greatly appreciated.

Thanks, Conor

A: 

Don't know if it may helps, but wolfram allows you to query distances (among other features), like:

distance from Los Angeles to New York

gives you this answer

But you can also query for coordinates, so maybe you can get the coordinates by users click on your map and query something like:

distance from 40.34N 74.00W to 40.34N 12.00W

Which gives you this result

Enrico Carlesso
Thanks for the replies guys but I don't think either of them have covered what I'm looking for.Essentially what I want is to make a GMap window that lets the use plot two points on the map. I think calculating the distance between the two points would be trivial by using the GMap API.
Conor H
+2  A: 

Since Google Maps uses latitude and longitude, you have to do a conversion to your preferred measure system to get the distance as the crow flies.

Here's one that uses kilometers;

var R = 6371; // km
var dLat = (lat2-lat1).toRad();
var dLon = (lon2-lon1).toRad(); 
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
        Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) * 
        Math.sin(dLon/2) * Math.sin(dLon/2); 
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
var d = R * c;

However, from the Google Maps v2 API you can get directional data from routes. Look into GDirections for the API reference. I've used it in one project, and it works fine.

Björn