我有这段代码:
function startTracking() {
var trackId = navigator.geolocation.watchPosition(successCallback, null, {maximumAge:1000, timeout:60000, enableHighAccuracy:true});
function successCallback(position){
map.panTo(new google.maps.LatLng(position.coords.latitude, position.coords.longitude));
var marker = new google.maps.Marker({
position: new google.maps.LatLng(position.coords.latitude, position.coords.longitude),
map: map,
title: 'Posizione Attuale'
});
marker.setMap(map);
};
}
现在应用程序每次移动时都会创建一个标记。我想,在地图上,我只看到我在那一刻的标记,我不会在前一个位置看到标记。
答案 0 :(得分:0)
我真的不知道api,但是例如:
function startTracking() {
//Destroy the marker here
var trackId = navigator.geolocation.watchPosition(successCallback, null, {maximumAge:1000, timeout:60000, enableHighAccuracy:true});
function successCallback(position){
map.panTo(new google.maps.LatLng(position.coords.latitude, position.coords.longitude));
var marker = new google.maps.Marker({
position: new google.maps.LatLng(position.coords.latitude, position.coords.longitude),
map: map,
title: 'Posizione Attuale'
});
marker.setMap(map);
};
}
setInterval(startTracking, 3000);
您可能希望将标记设为全局
答案 1 :(得分:0)
插入按钮进行刷新并解决问题..