Calculate distance between two points in google maps V3

后端 未结 15 1716
醉梦人生
醉梦人生 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:46

    //p1 and p2 are google.maps.LatLng(x,y) objects
    
    function calcDistance(p1, p2) {
              var d = (google.maps.geometry.spherical.computeDistanceBetween(p1, p2) / 1000).toFixed(2);
              console.log(d);              
    }
    

提交回复
热议问题