Distance between two points lat, lon

Is it possible to compare distances in the classical way (the distance between two points: d = sqrt(pow(lat2-lat1, 2) + pow(lon2-lon1, 2)) ) using the latitude and longitude returned from google apis without any conversions in meters or sth? I need this just for comparison, to find the closest point from a series of points to a control point. For instance:

Suppose we have two (lat, bosom) points: (40.2535425,22.88245345) and (40.2565795,22.8884539) and we want to find that the witch is closest (40.2335425,22.83245345). Can the above code be applied to find the distances? Or do we need to find the distance, say, in meters (using the haversin formula or something else), first for each point from the control point, and then compare the values?

I ask this question because I don’t know what exactly the values ​​returned by google apis are, like lat, lon! I mean that they are not deg-min-sec?

Thanks...

+6
google-maps latitude-longitude distance
source share
2 answers

No, because longitude lines converge to the poles. If your points are relatively close to each other, you can approach the distance this way:

 d = sqrt(pow(lat2-lat1, 2) + cos(lat1)*pow(lon2-lon1, 2)) 

If you need more accuracy over long distances, there are some fancy formulas for calculating the distances of a large circle , but it’s easier for me to convert to 3D coordinates on a unit circle, then do a simple Pythagorean distance and then 2 sin -1 (d / 2) to convert back to the corner (although I can understand that some may find not finding it easier :-).

+1
source share

You can also use computeDistanceBetween () from the new geometry library, which I think returns the distance in meters

+1
source share

All Articles