Calculate distance between two points in google maps V3

后端 未结 15 1717
醉梦人生
醉梦人生 2020-11-22 02:27

How do you calculate the distance between two markers in Google maps V3? (Similar to the distanceFrom function inV2.)

Thanks..

15条回答
  •  情话喂你
    2020-11-22 02:48

    With google you can do it using the spherical api, google.maps.geometry.spherical.computeDistanceBetween (latLngA, latLngB);.

    However, if the precision of a spherical projection or a haversine solution is not precise enough for you (e.g. if you're close to the pole or computing longer distances), you should use a different library.

    Most information on the subject I found on Wikipedia here.

    A trick to see if the precision of any given algorithm is adequate is to fill in the maximum and minimum radius of the earth and see if the difference might cause problems for your use case. Many more details can be found in this article

    In the end the google api or haversine will serve most purposes without problems.

提交回复
热议问题