views:

46

answers:

1

Hi all! I'm trying to update a Google Map (API V3) with markers using my friends locations stored in a database. I want to refresh the map every minute or so... kind of like google latitude which shows where yours friends are on the map.

Here is SOME of my Javascript: Please note that all i need to do is get a list of locations from the database, which in itself isnt hard... I just dont know how to update the javascript marker object with the Latitude and Longitude data of each entry every minute.

var map;
var markersArray = [];

function initialize() {
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
        zoom: 13,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}

function addMarker(location) {
    marker = new google.maps.Marker({
        position: location,
        map: map
    });
    markersArray.push(marker);
}

function addMarkerExisting(marker) {
    markersArray.push(marker);
}

// Removes the overlays from the map, but keeps them in the array
function clearOverlays() {
    if (markersArray) {
        for (i in markersArray) {
            marker.infowindow.close();
            markersArray[i].setMap(null);
        }
    }
}
A: 

My propose is to use something like this:

function initialize() {
...
setInterval("updateMarkers()",60000); //refresh every minute
}

and inside function updateMarkers() you have to clear markers from map and markers array and load&insert them again...

Royce