Google Maps API V3 infoWindow - All infoWindows displaying same content

前端 未结 2 497
滥情空心
滥情空心 2020-12-04 03:25

In my page, latitude, longitude and info window content are present in an array of objects named obj.

So if I need the latitude of property of the 1st object, I can

相关标签:
2条回答
  • 2020-12-04 03:50

    Should get you a long way.

    function attachMarker( data ) {
    
        var latLng = new google.maps.LatLng( data.latitude, data.longitude );
    
        var marker = new google.maps.Marker({
            position : latLng,
            map      : map, // global variable?
            icon     : prevIcon // global variable?
        });
    
        google.maps.event.addListener(marker, 'mouseover', function() {
           infowindow.setContent( data.text );
           infowindow.open(map, this);
        });
    
        // add marker here.
    
    }
    
    // afaik, you only need 1 instance of InfoWindow if you only change content.
    var infowindow = new google.maps.InfoWindow();
    
    var i = obj.length;
    while ( i-- ) {
        attachMarker( obj[ i ] );
    }
    
    0 讨论(0)
  • 2020-12-04 04:02

    BGerrissen's comment above helped a lot.

    I managed to achieve function closure on the info variable.

    The following Google Groups post explains how to.

    https://groups.google.com/group/google-maps-api-for-flash/browse_thread/thread/befeb9bf2d1ebcc9

    Thanks everyone :)

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