这个问题与其他问题非常相似,但我无法通过阅读它们来解决这个问题。
我正在创建一个带有信息窗口的自定义标记的地图。问题是,当fitBounds
功能正常工作时,标记不会显示在地图上。
你能帮帮我吗,我错过了什么?
我的代码:
var home_page_map = null;
function RenderHomePageMap(locations)
{
var home_page_bounds = new google.maps.LatLngBounds();
home_page_map = new google.maps.Map(document.getElementById('home-location-map'), {
center: {lat: 0.00, lng: 0.00},
zoom: 8
});
google.maps.event.addListenerOnce(home_page_map, 'idle', function(){
for(var i = 0; i < locations.length; i++)
{
if(locations[i]['coords']['longitude'] != '' && locations[i]['coords']['latitude'] != '')
{
var coords = new google.maps.LatLng(
parseFloat(locations[i]['coords']['latitude']),
parseFloat(locations[i]['coords']['longitude'])
);
var marker = new google.maps.Marker({
map: home_page_map,
position: coords,
//icon: ROOT_PATH + 'spa/img/mapmarker.png',
title: locations[i]['name'],
clickable: true
});
home_page_bounds.extend(marker.getPosition());
marker.info = new google.maps.InfoWindow({
content: ' \
<h4 attr-id="'+locations[i]['id']+'">'+locations[i]['name']+'</h4> \
<p>'+locations[i]['country']+', '+locations[i]['city']+', '+locations[i]['address']+'</p> \
'
});
google.maps.event.addListener(marker, 'click', function() {
marker.info.open(home_page_map, marker);
});
}
}
home_page_map.fitBounds(home_page_bounds);
});
}