1

我正在尝试添加详细信息以及 html 标签,但由于某种原因,我在 infowindow 中的标签无法识别。我已经在“contentString”中存储了带有地址的 div 标签。我已经声明了全局的 infowindow 变量,并且在我的 initializeMap 函数中我声明了 infowindow = new google.maps.InfoWindow();

提前谢谢了 ...

google.maps.event.addListener(marker, 'click', function () {

var geocoder = new google.maps.Geocoder();

geocoder.geocode({ 'latLng': marker.getPosition() }, function (results, status) {

   if (status == google.maps.GeocoderStatus.OK) {

       var address = results[1].formatted_address;

       var contentString = '<div>' + address + '<div>';

       infowindow.setContent(contentString);

       infowindow.open(map, this);
   }

 });
});
4

2 回答 2

2

可能是因为thisa 不是标记?尝试使用that

google.maps.event.addListener(marker, 'click', function () {
    var that = this;
    ...
    geocoder.geocode({ 'latLng': marker.getPosition() }, function (results, status) {
        ...
        infowindow.open(map, that);
    });
});
于 2013-06-29T18:14:13.360 回答
0

创建标记的完整功能,我使用从 nearBySearch 结果返回的每个服务调用该标记。

function createMarker(place) {

var IconType = {
   school: "../Icons/google_school.png",
   university: "../Icons/university.png",
};

var placeLoc = place.geometry.location;

var marker = new google.maps.Marker({
    map: map,
    position: placeLoc,
    icon: IconType[place.types[0]]
});

markers.push(marker);

google.maps.event.addListener(marker, 'click', function () {

var that = this;

var geocoder = new google.maps.Geocoder();

geocoder.geocode({ 'latLng': marker.getPosition() }, function (results, status) {

        if (status == google.maps.GeocoderStatus.OK) {

             var address = results[0].formatted_address;

   var infoWindow_content = '<div class="google_infoBlock">'+
                            '<div class="google_info_Title">' + place.name + '</div>'+
                            '<div class="google_info_address">' + address + '</div>' +
                            '</div>';

        infowindow.setContent(infoWindow_content);

        infowindow.open(map, that);
    }           
  });
 });
}

信息块CSS

.google_infoBlock {
   font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;    
}

.google_info_Title {
   color:#B0171F;
   font-size:16px;
 }

.google_info_address {
    color:#3d3d3d;
    font-size:14px;
}
于 2013-06-30T00:42:19.683 回答