Question

I have GPS tracking server and problem with clearing markers added with MarkerManager from database. My truncated code:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">  
<head>
<script src='http://maps.google.com/maps?file=api&amp;v=2&amp;hl=pl&amp;key=my_key' type='text/javascript'></script>
</head>   
<body onload='mapStart()' onunload='GUnload()'> 
<script type='text/javascript'>
var map;
var mgr=false;  
var timeOut=null;
function mapStart()
{
    if(GBrowserIsCompatible())
    {
    map = new GMap2(document.getElementById("map"),{mapTypes:     [G_NORMAL_MAP,G_HYBRID_MAP,G_SATELLITE_MAP,G_PHYSICAL_MAP]});
    center = new GLatLng(52.536395, 13.42534);
    map.setCenter(center, 6);
    mgr =  new GMarkerManager(map,{maxZoom: 19});
    refreshMarkers();
    }
}
function refreshMarkers()
{
    clearTimeout(timeOut);
    GDownloadUrl('dane2.php', function(dane,respCode)
    {
        if(respCode==200)
        {
            var xml = GXml.parse(dane);
            var marker = dodajMarker(arguments, 15, 15);
        }
        else
        {
            alert('Cant open dane2.php');
        }
    });
    mgr.clearMarkers(); // ???
    timeOut=setInterval("refreshMarkers()",2000);
}
function dodajMarker(arguments, minZoom, maxZoom)
{
    var ikona = new GIcon();
    ikona.image = 'http://www.google.com/intl/en_ALL/mapfiles/dd-start.png';
    ikona.iconSize = new GSize(20, 34);
    ikona.iconAnchor = new GPoint(10, 34);
    var marker = new GMarker(new GLatLng(latitude,longitude),{icon: ikona});
    mgr.addMarker(marker,minZoom,maxZoom);
    return marker;
}

</script>
<div id="map" style="align: center; width: 1000px; height: 490px; solid black;     background: gray;"></div>
</body>   
</html>

My page: http://m2mgsm.com/gps/index.php You can login: "admin", password: "12345" Click Test Map ("Mapatesty" - polish language only, english soon) in menu and then Select IMEI ("Wybierz IMEI") e.g. 355832010123229 and check Route ("Pokaż trasę:") and From/To ("Od/Do") date (e.g. 05.01.2012/05.01.2012) and "Filtruj". You can now view source of my map script in frame. I want to refresh ONLY markers with e.g. 3 sec. interval and it works, but new markers are OVERLAY on old markers... Ps. Sorry for my English.

Was it helpful?

Solution

You have errors is your JS:

ReferenceError: kontener is not defined [http://m2mgsm.com/gps/mapatesty.php:259]
TypeError: Object #<yv> has no method 'clearMarkers' [http://m2mgsm.com/gps/mapatesty.php:459]

Try to use Firefox with Firebug extension or Chrome with its built-in Debugger to trace through your JavaScript code and eliminate the bugs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top