简体   繁体   中英

Update Google Maps Javascript objects every 1 min using fresh data from database using C#?

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

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM