Google Maps - Multiple markers - 1 InfoWindow problem

后端 未结 5 877
一整个雨季
一整个雨季 2020-12-09 23:18

I can\'t get my markers to display different infowindows. The markers always display the content of the last \"contentString\".

I\'ve read a few other posts but none

5条回答
  •  执笔经年
    2020-12-09 23:57

    One way you can get seriously dynamic info into an infoWindow, assuming you have php or such like is to set content of infoWindow as an iframe with src that takes info from the position or ID of the marker in question. So in initialize function or wherever.

    var pos_info = new google.maps.InfoWindow({pixelOffset: new google.maps.Size(0, -5), maxWidth: 350, position: posit, ID: "pos_i"});
    
    var pos_mark = new google.maps.Marker({map: map, position: posit, clickable: true, draggable: true, ID: "pos_m", icon: therm2});
    
    pos_mark.addListener('mouseup', function () {
    var lat = pos_mark.getPosition().lat();
    lat = lat.toFixed(4)
    var lng = pos_mark.getPosition().lng();
    lng = lng.toFixed(4)
    var contentString = ""
    pos_info.setContent(contentString);
    pos_info.open(map, pos_mark);
    })
    

提交回复
热议问题