6

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.

TJP
  • 121
  • 2
  • 5

2 Answers2

5

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

Trevor
  • 6,659
  • 5
  • 35
  • 68
4

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.

Community
  • 1
  • 1
mpdonadio
  • 2,891
  • 3
  • 35
  • 54