我正在尝试在谷歌地图上创建一个标记以显示用户当前位置。使用以下代码我可以做到这一点,但每次 watchPosition 刷新它都会创建一个新点。每次添加新点时如何清除以前的标记?
// Geolocation
var win = function(position) {
var iconimage = new google.maps.MarkerImage('images/current_location_small.png',
new google.maps.Size(15, 15),
new google.maps.Point(0,0),
new google.maps.Point(7, 7)
);
var lat = position.coords.latitude;
var long = position.coords.longitude;
var myLatlng = new google.maps.LatLng(lat, long);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
icon: iconimage
});
marker.setMap(map);
};
var watchID = navigator.geolocation.watchPosition(win);