An array of infoWindow in Google maps api

后端 未结 2 750
逝去的感伤
逝去的感伤 2021-01-26 08:14

I looked for error and I couldn\'t find it. Any google maps infoWindow always shows the same information for some reason.

Here is a coffeescript code

inf         


        
相关标签:
2条回答
  • 2021-01-26 08:51

    you need to obtain closure on the variable company. You can do that by creating your markers in a separate function. for example:

    infowindow = new google.maps.InfoWindow()
    for(var n = 0 ; n < n companiesData.length ;n++){
      createMarker(companiesData[n]);
    }
    
    function createMarker(data){
      var marker = new google.maps.Marker({
        position: new google.maps.LatLng(parseFloat(data.latitude), parseFloat(data.longitude)),
        map: map
      })
    
      #debugger ---> each company.name is different!
      google.maps.event.addListener(marker, 'click', function(){
        infowindow.setContent(data.name);
        infowindow.open(map,this);
      }
      )
    }
    

    Explanation here.

    0 讨论(0)
  • 2021-01-26 08:55

    I had the same... try to create marker in separate function. It helped for me.

    Check it out: https://developers.google.com/maps/articles/phpsqlsearch_v3

    Find code with "searchLocationsNear(center)" function.

    0 讨论(0)
提交回复
热议问题