我是一名新手,第一次接触StackOverflow和编程。您好!
我想知道如何在JavaScript的Google地图上刷新PHP数据的经纬度,因为经纬度每秒钟都在变化,我想实时刷新经纬度。但问题是只有在第一次加载真实位置时才会加载,并且仅刷新相同的经纬度。如何在不重新加载页面的情况下从PHP中加载经纬度?
在这个文件中,PHP的代码段负责加载Google地图。
<script>
function initMap() {
var myLatlng = new google.maps.LatLng('.json_encode($Lat).', '.json_encode($Long).');
var mapOptions = {
zoom: 13,
center: myLatlng
}
var map = new google.maps.Map(document.getElementById("map"), mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
});
marker.setMap(map);
setInterval( function(){
marker.setPosition( new google.maps.LatLng( '.json_encode($Lat).', '.json_encode($Long).' ) );
map.panTo( new google.maps.LatLng( '.json_encode($Lat).', '.json_encode($Long).' ) );
}, 1000 );
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=myapikey&callback=initMap">
</script>