簡體   English   中英

拖動時獲取谷歌地圖中心的經度和緯度

[英]Get Latitude and Longitude of the center in google map when dragged

當我將google地圖移動到任何方向時,我想提醒中心點的緯度和經度。 我怎樣才能做到這一點。 實際上我下面的代碼在移動條件下不起作用。

   //Javascript For Google Map
var map;
function initialize() {
    var mapOptions = {
            center: { lat: -34.397, lng: 150.644},
            zoom: 8
    };
    var map = new google.maps.Map(document.getElementById('map-canvas'),
            mapOptions);
    var center = map.getCenter();
    var lat = center.latitude;
    var long = center.longitude;
    google.maps.event.addDomListener(map, 'dragend', getMinMaxLatLong(center));
}
google.maps.event.addDomListener(window, 'load', initialize);

function getMinMaxLatLong(lat,long) {
    alert(lat+'==='+long);return false;
    $.get('getLatLong.php?lat='+latitue+'&long='+longitude+'&radius=20&unit=mi&type=cities',function(data){
        alert(data);
    });
}

當我移動或拖動地圖時,應該更改中心緯度。

也許是因為您使用的dragend事件僅在拖動停止時才觸發。 我認為您應該使用以下drag事件:

google.maps.event.addDomListener(map, 'drag', getMinMaxLatLong(center));

考慮使用空閑事件而不是dragend

當地圖在平移或縮放后變得空閑時,將觸發此事件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM