谷歌地图标记 - infowindow

时间:2016-01-10 22:22:15

标签: javascript google-maps infowindow

我需要在InfoWindow中显示match.offer.text。 每个标记都有不同的match.offer.text。

这是我的代码:

var markerImageURL, lat, lng;
if (myoffer) {
    markerImageURL = 'assets/img/markers/marker_my.png';
    lat = match.lat;
    lng = match.lng;
} else {
    markerImageURL = 'assets/img/markers/marker_' + match.strength + '.png';
    lat = match.offer.lat;
    lng = match.offer.lng;
}

var marker = new google.maps.Marker({
    position: new google.maps.LatLng(lat, lng),
    map: window.googleMap,
    icon: {
        size: new google.maps.Size(54,56),
        url: markerImageURL
    },
    draggable: false,
    visible: true
});

var infowindow = new google.maps.InfoWindow({
    content: match.offer.text,
    maxWidth: 300
});

window.googleMapMarkers.push(marker);

if(!myoffer) {
    window.MVC.Events.GoogleMap.prototype.showInfoWindow(marker, infowindow, match);
}

点击标记后触发事件:

marker.addListener('click', function() {
    infowindow.open(window.googleMap, marker);
}

请帮助我。

1 个答案:

答案 0 :(得分:1)

内容将应用于Open上的标记,因此您的代码会将循环中最后一项中的内容应用于所有标记,在openWindow函数中将内容添加到单个infoWindow对象,即

Maps API也有自己的Click事件包装器

#include <stdio.h>
#include <math.h>

int main()
{
    double GoldenMeanA;
    double GoldenMeanB;
    int i;
    int F;
    float x;

    printf ("The Fibonocci numbers are   ");
    for ( i = 1; i < 7 ; i++ )
    {  
        GoldenMeanA = pow(1.6180339887, i);
        GoldenMeanB = pow(-.6180339887, i);
        x = ((GoldenMeanA) - (GoldenMeanB)) / (sqrt (5));
        F=(int)(x+0.1);
        printf("%d  ", F); 
    }
    return 0;
}
相关问题