【发布时间】:2014-10-22 06:41:30
【问题描述】:
我正在使用gmaps.js 来显示一个基本的谷歌地图,并在当前位置放置一个标记。我将纬度和经度坐标存储在变量中,并使用它们来定义经度和纬度。纬度和经度变量从我的服务器不断更新。发生这种情况时,地图会在地图上的新位置显示标记,但会刷新整个地图。我只想更新标记并保持地图不刷新。有没有办法做到这一点?
<script>
var map;
var Latitude = //this is being updated from my server constantly
var Longitude = //this is being updated from my server constantly
$(document).ready(function(){
map = new GMaps({
el: '#map',
lat: Latitude,
lng: Longitude
});
map.addMarker({
lat: Latitude,
lng: Longitude,
title: 'Lima',
details: {
database_id: 42,
author: 'HPNeo'
},
click: function(e){
if(console.log)
console.log(e);
alert('You clicked in this marker');
},
mouseover: function(e){
if(console.log)
console.log(e);
}
});
map.addMarker({
lat: -12.042,
lng: -77.028333,
title: 'Marker with InfoWindow',
infoWindow: {
content: '<p>HTML Content</p>'
}
});
});
</script>
【问题讨论】:
-
当然,保留对标记的引用并更新其坐标。
标签: javascript