我需要两件事
1)没有页面刷新的实时更新 2)标记上的标记,用于标识谁在哪里。
我遇到的这些代码通过JS将标记放在地图上,但没有刷新就没有实时更新。
<html>
<head>
<script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<style>
#map-canvas
{
height: 400px;
width: 500px;
}
</style>
</head>
<body>
<div id="map-canvas"></div>
<script>
var myLatLng = new google.maps.LatLng( 54.0239304,-1.5453314000000091 ),
myOptions = {
zoom: 4,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
},
map = new google.maps.Map( document.getElementById( 'map-canvas' ), myOptions ),
marker = new google.maps.Marker( {position: myLatLng, map: map} );
marker.setMap( map );
setTimeout( function(){
marker.setPosition( new google.maps.LatLng( 54.0239304,-1.5453314000000091 ) );
map.panTo( new google.maps.LatLng( 54.0239304,-1.5453314000000091 ) );
}, 1500 );
</script>
</body>
</html>
非常感谢有关此主题的任何帮助。
答案 0 :(得分:2)
“实时更新” - 当您收到新的传入数据时,您必须检查传入数据的ID(如果它有ID)并检查当前是否有任何标记具有该地图上的ID。 myOptions只是一个对象,所以你可以在那里添加你的id(即“markerId:1234567”)。