Google maps api 3 带有html标记和css样式的google地图标记信息窗口
我试图在添加html标记的同时添加细节,但由于某些原因,我在infowindow中的标记无法识别。我在“contentString”中存储了地址为的div标记。我声明了infowindow变量global,并在initializeMap函数中声明infowindow=new google.maps.infowindow() 非常感谢Google maps api 3 带有html标记和css样式的google地图标记信息窗口,google-maps-api-3,google-maps-markers,Google Maps Api 3,Google Maps Markers,我试图在添加html标记的同时添加细节,但由于某些原因,我在infowindow中的标记无法识别。我在“contentString”中存储了地址为的div标记。我声明了infowindow变量global,并在initializeMap函数中声明infowindow=new google.maps.infowindow() 非常感谢 google.maps.event.addListener(marker, 'click', function () { var geocoder = new g
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);
}
});
});
google.maps.event.addListener(标记,'click',函数(){
var geocoder=new google.maps.geocoder();
geocoder.geocode({'latLng':marker.getPosition()},函数(结果,状态){
if(status==google.maps.GeocoderStatus.OK){
var address=results[1]。格式化的\u地址;
var contentString=''+地址+'';
setContent(contentString);
打开(地图,这个);
}
});
});
可能是因为这个不是标记?试着使用那
:
google.maps.event.addListener(marker, 'click', function () {
var that = this;
...
geocoder.geocode({ 'latLng': marker.getPosition() }, function (results, status) {
...
infowindow.open(map, that);
});
});
完成创建标记的函数,我使用从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);
}
});
});
}
您在关闭
标记时出错:应该是
这是不完整的;您不会显示如何创建信息窗口。请在JSFIDLE中输入完整的代码。@您能打开信息窗口吗?我以前尝试过使用正确的/div标记,但错过了这里。。。不过,感谢您的解决方案…非常感谢Tomas它的工作原理。。。它担心我没有真正得到那个,因为我使用同一个制造商来获得拉特朗坐标@您可以使用相同的标记,但谁知道在传递给geocode的函数中如何设置此。。。如果我的变通方法有效,那是因为这个;-)这是一个常见的错误
.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;
}