0

What will be the best way (or) Is there a Google's way already to Calculate the simple Straight Line Distance between Two Points, based on Lat/Lng or even on Postal/Zip Code is possible?

1
  • what language are you using? Or are you trying to do this with Google Maps?
    – geocodezip
    Jan 16, 2013 at 18:38

4 Answers 4

1

I found the answer by myself, from somewhere else.

Yes, there is a native solution from Google already, at: https://developers.google.com/maps/documentation/javascript/reference?hl=en-US#spherical

All I need to do is to call the method: 'google.maps.geometry.spherical.computeDistanceBetween (latLngA, latLngB);'

(Ofcourse I also need to include the additional/required '.js')

1
  • From the google name spacing I'd assume this is spherical distance and not "straight" as you stated in your question. (I'm looking for the same thing, but I want a cheap calculation)
    – Aidan Ewen
    Jan 20, 2016 at 13:38
0

"Best" is a pretty vague criterion. If you're able to assume the earth is a perfect sphere, then you want the simple formula for great circle distance. See for example the Wikipedia article. With this assumption your distance can be off by something less than half a percent.

The actual shape of the earth is actually a slightly oblate spheroid. The surface distance on this shape is more complicated to compute. See Ed Williams' work in javascript. Maybe he will let you use his code. If not he gives relevant references.

0

A free solution is at http://ezcmd.com/apps/app_ezip_locator#ezip_locator_api

Can help you find distance between two lat,long coordinates in miles or Km.

Or, you could try http://ezcmd.com/apps/app_geo_postal_codes#geo_postal_codes_api

-1

The "best" way depends on several things. Can you provide a little more background as to how accurate and/or what's the desired application? The google.maps.DirectionsService class will allow you to calculate the driving distance client side with javascript, but if you want an accurate straight line distance you could use postgresql + postgis server side. Calculating accurate distances with lat/lng can get tricky with the different projections of the earth depending on the range of points and distances involved.

9
  • Sorry, i mean just simple straight Distance, whatever the geography is there between. Jan 16, 2013 at 17:56
  • calculating straight distances with lat/lng coordinates uses some fairly complex formulas depending on the distances involved, but one way to get a "simple" all around the world accurate straight line distance would be to do a distance query in postgresql + postgis
    – scrivy
    Jan 16, 2013 at 18:04
  • How important is accuracy? the world just isn't as round as you'd like it to be :-P
    – scrivy
    Jan 16, 2013 at 18:05
  • like, straight through the earth?
    – argentage
    Jan 16, 2013 at 23:24
  • unless the point distance being calculated is projected onto a 2d plane (to make the math simpler) straight generally implies taking the curvature of the earth into account
    – scrivy
    Jan 16, 2013 at 23:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.