Calculate distance between two points in google maps V3

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

    Example using GPS latitude/longitude of 2 points.

    var latitude1 = 39.46;
    var longitude1 = -0.36;
    var latitude2 = 40.40;
    var longitude2 = -3.68;
    
    var distance = google.maps.geometry.spherical.computeDistanceBetween(new google.maps.LatLng(latitude1, longitude1), new google.maps.LatLng(latitude2, longitude2));       
    

提交回复
热议问题