HTML5 地理位置信息 window 不工作

HTML5 geolocation info window not working

我需要从这段代码中创建信息-window,我缺乏应用程序逻辑并且完全不熟悉编程我使用这个open-source code

此代码将用户及其标记添加到地图

    function loadMarkers(data) {
    for(key in data) {
        var user = data[key];
        xmartlabschat.addUser(user);
        markers[key] = getMarker(user.lat, user.lng, user.name);
    }
}

我尝试使用基本代码获取信息-window

var infoWindow = new google.maps.InfoWindow(user.name);
markers[key].addListener('click', function(){
        infoWindowMe.open(map,markers[key);

但是此代码将所有标记变成与用户相同的名称而不是不同的名称,因为我单击了其他用户标记

请帮忙 Here the screenshot I took

你可以试试这个。希望这有帮助。

var locations = [
['Location name', LAT, LON],
['...', ..., ...],
//...
];

var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 8,
    center: new google.maps.LatLng(LAT, LON),
    mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();

var marker, i; 
for (i = 0; i < locations.length; i++) {
    var lat = locations[i][1];
    var lng = locations[i][2];
    marker = new google.maps.Marker({
        position: new google.maps.LatLng(lat, lng),
        map: map,
    }); // generates all the markers
    google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
            zIndex: 1000;
            infowindow.setContent(locations[i][0]); // replace locations[i][0] with which data you want to show
            infowindow.open(map, marker);
        }
    })(marker, i)); // generates corresponding info-window
}