首页 文章

如何使用google maps api生成纬度和经度以及源和目标纬度

提问于
浏览
-2

我正在研究谷歌 Map api,

我需要使用源和目标lat / longs生成纬度和经度 .

任何人都可以帮忙,需要应用的公式是什么,以及生成源和目的地之间的纬度和经度 . 是否有任何公式可以计算,并且从源到目的地的纬度很长 .

Please check this image you will get an idea

1 回答

  • 0

    您需要Geocoder才能获得特定位置的纬度和经度 .

    var startingPoint = 'your location';
    var latitude, longitude, map, geocoder = new google.maps.Geocoder();
    
    geocoder.geocode({'address': startingPoint}, function(results, status){
        //console latitude & longitude of your location
        latitude = results[0].geometry.location.lat();
        longitude = results[0].geometry.location.lng();
        console.log("Latitude - " + latitude);
        console.log("Longitude - " + longitude);
    
        if(status == 'OK'){
            map = new google.maps.Map(document.getElementById('map'), {
                center: {lat: results[0].geometry.location.lat(), lng: results[0].geometry.location.lng()},
                zoom: 15
            }); 
        } else {
            console.log("Geocode not working - " + status);
        }
    });
    

    有关google maps api的更多信息,请参阅此link .

相关问题