working out distances between two points using google maps api?

后端 未结 8 1376
北海茫月
北海茫月 2021-01-03 10:39

Is it possible to send two lat long points to google to calculate the distance between the two?

8条回答
  •  耶瑟儿~
    2021-01-03 11:06

    Yes google can do this

    google api docs

    here's a piece of java script that get's the distance in km's for two points

    function initialize() {
          if (GBrowserIsCompatible()) {
              map = new GMap2(document.getElementById("map_canvas"));
              map.setCenter(new GLatLng(52.6345701, -1.1294433), 13);
              map.addControl(new GLargeMapControl());          
              map.addControl(new GMapTypeControl());
              geocoder = new GClientGeocoder();
    
              // NR14 7PZ
              var loc1 = new GLatLng(52.5773139, 1.3712427);
              // NR32 1TB
              var loc2 = new GLatLng(52.4788314, 1.7577444);          
              alert(loc2.distanceFrom(loc1) / 1000);
          }
        }
    
    

提交回复
热议问题