Google maps 谷歌地图API信息窗口无法打开
我在我的网站上使用谷歌地图,效果很好。但如果我使用自己的标记图像,则信息窗口将不再弹出。有人知道为什么吗 你可以在没有我自己的标记的情况下看到整个项目Google maps 谷歌地图API信息窗口无法打开,google-maps,google-maps-api-3,google-maps-markers,Google Maps,Google Maps Api 3,Google Maps Markers,我在我的网站上使用谷歌地图,效果很好。但如果我使用自己的标记图像,则信息窗口将不再弹出。有人知道为什么吗 你可以在没有我自己的标记的情况下看到整个项目 函数initMap(){ var map=new google.maps.map(document.getElementById('map'){ 缩放:6, 中心:{lat:50.984768,lng:11.029880} }); 设置标记(地图); } var集合=; 函数设置标记(map){ 变量图像={ url:'img/markerBlu
函数initMap(){
var map=new google.maps.map(document.getElementById('map'){
缩放:6,
中心:{lat:50.984768,lng:11.029880}
});
设置标记(地图);
}
var集合=;
函数设置标记(map){
变量图像={
url:'img/markerBlue.png'
};
对于(变量i=0;i
这里有关于自定义标记的文档,其中包括一个JSFIDLE示例:
我已经修改了上面文档中的示例,以便在按下标记时弹出一个信息窗口。请在这里查看我的小提琴(注意:您需要将API密钥添加到代码中才能使其工作,出于安全考虑,我删除了我的):
自定义标记图标的代码示例:
var iconBase = 'https://maps.google.com/mapfiles/kml/shapes/';
var icons = {
parking: {
icon: iconBase + 'parking_lot_maps.png'
},
library: {
icon: iconBase + 'library_maps.png'
},
info: {
icon: iconBase + 'info-i_maps.png'
}
};
var infowindow = new google.maps.InfoWindow({
content: 'this is a test'
});
function addMarker(feature) {
var marker = new google.maps.Marker({
position: feature.position,
icon: icons[feature.type].icon,
map: map
});
marker.addListener('click', function() {
infowindow.open(map, marker);
});
}
var features = [
{
position: new google.maps.LatLng(-33.91721, 151.22630),
type: 'info'
}, {
position: new google.maps.LatLng(-33.91539, 151.22820),
type: 'info'
}, {
position: new google.maps.LatLng(-33.91747, 151.22912),
type: 'info'
}, {
position: new google.maps.LatLng(-33.91910, 151.22907),
type: 'info'
}, {
position: new google.maps.LatLng(-33.91725, 151.23011),
type: 'info'
}, {
position: new google.maps.LatLng(-33.91872, 151.23089),
type: 'info'
}, {
position: new google.maps.LatLng(-33.91784, 151.23094),
type: 'info'
}, {
position: new google.maps.LatLng(-33.91682, 151.23149),
type: 'info'
}, {
position: new google.maps.LatLng(-33.91790, 151.23463),
type: 'info'
}, {
position: new google.maps.LatLng(-33.91666, 151.23468),
type: 'info'
}, {
position: new google.maps.LatLng(-33.916988, 151.233640),
type: 'info'
}, {
position: new google.maps.LatLng(-33.91662347903106, 151.22879464019775),
type: 'parking'
}, {
position: new google.maps.LatLng(-33.916365282092855, 151.22937399734496),
type: 'parking'
}, {
position: new google.maps.LatLng(-33.91665018901448, 151.2282474695587),
type: 'parking'
}, {
position: new google.maps.LatLng(-33.919543720969806, 151.23112279762267),
type: 'parking'
}, {
position: new google.maps.LatLng(-33.91608037421864, 151.23288232673644),
type: 'parking'
}, {
position: new google.maps.LatLng(-33.91851096391805, 151.2344058214569),
type: 'parking'
}, {
position: new google.maps.LatLng(-33.91818154739766, 151.2346203981781),
type: 'parking'
}, {
position: new google.maps.LatLng(-33.91727341958453, 151.23348314155578),
type: 'library'
}
];
for (var i = 0, feature; feature = features[i]; i++) {
addMarker(feature);
}
我希望这有帮助 嘿,伙计,谢谢你的帮助。这不是我想要的,但它帮助我找到了解决方案。Thx 我忘了在函数placeMarker()中添加图标 现在我拿到了,效果很好。谢谢:-)
功能位置标记(loc){
var latLng=新的google.maps.latLng(loc[1],loc[2]);
var marker=new google.maps.marker({
位置:latLng,
图标:icons.icon,
地图:地图
});
google.maps.event.addListener(标记'click',函数(){
infowindow.close();//关闭以前打开的infowindow
infowindow.setContent(“+loc[3]+”);
信息窗口。打开(地图、标记);
});
}
var iconBase = 'https://maps.google.com/mapfiles/kml/shapes/';
var icons = {
parking: {
icon: iconBase + 'parking_lot_maps.png'
},
library: {
icon: iconBase + 'library_maps.png'
},
info: {
icon: iconBase + 'info-i_maps.png'
}
};
var infowindow = new google.maps.InfoWindow({
content: 'this is a test'
});
function addMarker(feature) {
var marker = new google.maps.Marker({
position: feature.position,
icon: icons[feature.type].icon,
map: map
});
marker.addListener('click', function() {
infowindow.open(map, marker);
});
}
var features = [
{
position: new google.maps.LatLng(-33.91721, 151.22630),
type: 'info'
}, {
position: new google.maps.LatLng(-33.91539, 151.22820),
type: 'info'
}, {
position: new google.maps.LatLng(-33.91747, 151.22912),
type: 'info'
}, {
position: new google.maps.LatLng(-33.91910, 151.22907),
type: 'info'
}, {
position: new google.maps.LatLng(-33.91725, 151.23011),
type: 'info'
}, {
position: new google.maps.LatLng(-33.91872, 151.23089),
type: 'info'
}, {
position: new google.maps.LatLng(-33.91784, 151.23094),
type: 'info'
}, {
position: new google.maps.LatLng(-33.91682, 151.23149),
type: 'info'
}, {
position: new google.maps.LatLng(-33.91790, 151.23463),
type: 'info'
}, {
position: new google.maps.LatLng(-33.91666, 151.23468),
type: 'info'
}, {
position: new google.maps.LatLng(-33.916988, 151.233640),
type: 'info'
}, {
position: new google.maps.LatLng(-33.91662347903106, 151.22879464019775),
type: 'parking'
}, {
position: new google.maps.LatLng(-33.916365282092855, 151.22937399734496),
type: 'parking'
}, {
position: new google.maps.LatLng(-33.91665018901448, 151.2282474695587),
type: 'parking'
}, {
position: new google.maps.LatLng(-33.919543720969806, 151.23112279762267),
type: 'parking'
}, {
position: new google.maps.LatLng(-33.91608037421864, 151.23288232673644),
type: 'parking'
}, {
position: new google.maps.LatLng(-33.91851096391805, 151.2344058214569),
type: 'parking'
}, {
position: new google.maps.LatLng(-33.91818154739766, 151.2346203981781),
type: 'parking'
}, {
position: new google.maps.LatLng(-33.91727341958453, 151.23348314155578),
type: 'library'
}
];
for (var i = 0, feature; feature = features[i]; i++) {
addMarker(feature);
}
function placeMarker(loc) {
var latLng = new google.maps.LatLng( loc[1], loc[2]);
var marker = new google.maps.Marker({
position : latLng,
icon: icons.icon,
map : map
});
google.maps.event.addListener(marker, 'click', function(){
infowindow.close(); // Close previously opened infowindow
infowindow.setContent( "<div id='infowindow'>"+ loc[3] +"</div>");
infowindow.open(map, marker);
});
}