嘗試通過sql數據庫中的經/緯度坐標間隔移動標記/地圖。function initialize() { var myLatLng = new google.maps.LatLng(41,14); var myOptions = { zoom: 16, center: myLatLng, scrollwheel: false, panControl: true, zoomControl: true, mapTypeControl: true, scaleControl: true, streetViewControl: true, overviewMapControl: true, mapTypeId: google.maps.MapTypeId.SATELLITE, } map = new google.maps.Map(document.getElementById('map_canvas'), myOptions); marker = new google.maps.Marker({ position: myLatLng, map: map, draggable: false});}google.maps.event.addDomListener(window, 'load', initialize);function getCoords() {$.ajax({url: "../ajaxscript.php",type: "POST",data: {foo : "bar"},dataType: "text",success: function(returnedData) { alert(returnedData); moveMarkerMap(returnedData);}});}function moveMarkerMap(newCoords) {var newLatLang = new google.maps.LatLng(newCoords);map.panTo(newLatLang);marker.setPosition(newLatLang);}window.setInterval(getCoords, 5000);在moveMarkerMap()中設置新的google.maps.LatLng(14,41)會移動它,并且returnData顯示在alert()中,但與moveMarkerMap()一起使用時標記不會移動從ajax返回的字符串格式正確;(9.624672,7.242244)如alert()所示,因此不確定為什么它不起作用。
谷歌地圖從ajax成功返回數據的經度/緯度移動標記
開滿天機
2020-02-02 15:41:35