Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating "As the crow flies" distances wtih Google Maps API

I'm fairly helpless here guys so hoping for some good ideas easily executed.

Basically I have a form filed tied into Google Maps that will let someone type an address and assign it a lat/long. I'd like to add another one, store both of the inputs people enter and then calculate the "as the crow flies" distance.

I just want to give it an address and have it output how far those addresses are from one another, on a linear line. If it could show that on a map overlay, all the better.

I've been hunting for examples but everything I find has a lot of feature bloat. I just want some simple source code I could study doing this basic type of function.

This is where I am at currently:

http://www.public.asu.edu/~tpeiffer/

Would LOVE any and all thoughts.

like image 283
TJP Avatar asked Mar 27 '11 23:03

TJP


2 Answers

Google Maps V2: http://code.google.com/apis/maps/documentation/javascript/v2/reference.html#GLatLng.distanceFrom

Google Maps V3: computeDistanceBetween(from:LatLng, to:LatLng, radius?:number) http://code.google.com/apis/maps/documentation/javascript/reference.html#spherical

like image 103
Trevor Avatar answered Sep 27 '22 19:09

Trevor


Trevor gave the answer using the Google Maps API, but also check out this question, Calculate distance between two latitude-longitude points? (Haversine formula), and in particular, the link in the accepted answer.

like image 42
mpdonadio Avatar answered Sep 27 '22 19:09

mpdonadio