为每个标记添加信息窗口

时间:2013-12-03 17:24:58

标签: google-maps infowindow

我已成功将多个标记添加到Google地图,现在我想为每个标记添加一个信息窗口。我尝试了多种方法,没有运气。

如果在点击标记时弹出property_title的信息窗口,我想要的是什么。

这是我到目前为止所拥有的。

var data = 

{ "property": [
{"property_id": 1, "property_title": "property 1", "property_img": "imag1", "longitude": 1234, "latitude": 1234, "width": 500, "height": 375},
{"property_id": 2, "property_title": "property 2", "property_img": "imag1", "longitude": 1234, "latitude": 1234, "width": 500, "height": 375},
{"property_id": 3, "property_title": "property 3", "property_img": "imag1", "longitude": 1234, "latitude": 1234, "width": 500, "height": 375},
{"property_id": 4, "property_title": "property 4", "property_img": "imag1", "longitude": 1234, "latitude": 1234, "width": 500, "height": 375},
{"property_id": 5, "property_title": "property 5", "property_img": "imag1", "longitude": 1234, "latitude": 1234, "width": 500, "height": 375}
]};             

    var markers = [];
    for (var i = 0; i < 5; i++) {
      var dataProperty = data.property[i];
      var latLng = new google.maps.LatLng(dataProperty.latitude,
          dataProperty.longitude);
      var marker = new google.maps.Marker({
        position: latLng
      });
      markers.push(marker);
    }

2 个答案:

答案 0 :(得分:0)

你试过这个Google Maps JavaScript API v3

吗?

答案 1 :(得分:0)

请参阅下面的工作演示。

http://jsfiddle.net/RJPKJ/1/

for (i = 0; i < 5; i++){                       
var dataProperty = dataitem.property[i];     
latitudetest =dataProperty.latitude;
longitudetest = dataProperty.longitude;
var data= dataProperty.property_title;    
var myLatlng = new google.maps.LatLng(latitudetest, longitudetest);
}