GoogleMap Markers are Not Clickable on the Mobile Devices

前端 未结 2 1940
日久生厌
日久生厌 2021-01-21 15:22

GoogleMap Markers are Not Clickable on the Mobile Devices (Touch Screens).
But, ok on any PC, so I can\'t figure out what is the point.
Here is my code:

2条回答
  •  情深已故
    2021-01-21 15:57

    The problem is because you're doing a loop, you need to use a closure, otherwise all markers will just get the content you want to associate with the last marker. Your first bit of code is doing this correctly. Suggest you change to do the same again:

    var infowindow = new google.maps.InfoWindow({content: locations[i][0]});
    google.maps.event.addListener( marker, 'click', function(marker, i) {
      return function() {
        infowindow.setContent(locations[i][0]);
        infowindow.open(map,this);
      }
    })(marker, i));
    

提交回复
热议问题