简体   繁体   English

使用C#使用数据库中的新鲜数据每1分钟更新一次Google Maps Javascript对象吗?

[英]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. 我正在尝试使用存储在数据库中的朋友位置使用标记来更新Google Map(API V3)。 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. 这是我的Javascript的一部分:请注意,我要做的就是从数据库中获取位置列表,这本身并不困难...我只是不知道如何使用纬度和经度数据更新javascript标记对象每分钟的条目数。

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... 在功能updateMarkers()中,您必须从地图和标记数组中清除标记,然后再次加载并插入它们...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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