Javascript HTML5,带标记的实时地理定位

Javascript HTML5,带标记的实时地理定位,javascript,html,google-maps-api-3,marker,Javascript,Html,Google Maps Api 3,Marker,我有以下代码: function startTracking() { var trackId = navigator.geolocation.watchPosition(successCallback, null, {maximumAge:1000, timeout:60000, enableHighAccuracy:true}); function successCallback(position){ map.panTo(new google.maps.Lat

我有以下代码:

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);  


    };

}

现在,每次我移动时,应用程序都会创建一个标记。我希望,在地图上,我只看到我当时所在的标记,而不会看到前面位置的标记。

我不太了解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);

您可能希望将标记设置为全局

插入刷新按钮并解决此问题。

如果删除标记,您可以删除此标记并调用startTracking with setInterval(),在此处写入标记的创建?调用函数后?我使用“marker.setMap(null);”对于destroy marker,但现在我看不到任何东西,我不知道,我正在使用类似的东西,但使用openlayers。我们的想法是删除它并重新创建它。你必须对此进行搜索。