我一直在搜索 Google Map Api 关于此问题的所有回复,但未能提出解决方案。
我有一个 javascript 数组“js_pickup_location_info”,其中包含 17 个对象,包括所有经纬度信息。我正在尝试遍历并在谷歌地图上显示所有 17 个标记。然而,17 个标记中只有 8 个出现在地图上。下面是代码。
谢谢你的帮助。
function initialize() {
var myLatlng = new google.maps.LatLng(myLat,myLong);
var mapOptions = {
zoom: 14,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var c= js_pickup_location_info.length;
console.log(c);
for (var i=0; i<c; i++){
pickup_id= js_pickup_location_info[i]['pickup_id'];
pickup_latlng= new google.maps.LatLng(js_pickup_location_info[i]['latitude'],js_pickup_location_info[i]['longitude']);
contentString= '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h2 id="firstHeading" class="firstHeading">'+js_pickup_location_info[i]['address']+'</h2>'+
'<div id="bodyContent">'+
'<p>'+js_pickup_location_info[i]['pickup_day']+'</p>'+
'<p>HOLDER Insert Ajax Link</p>'+
'</div>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
// could add size: new google.maps.Size(50,50)
});
var marker = new google.maps.Marker({
position: pickup_latlng,
map: map,
title: pickup_id
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
}
}
function loadScript() {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.googleapis.com/maps/api/js?key=AIzaSyCH-RktY6ZGD8AlwxEzzF28nzCrRMjEfjE&sensor=false&callback=initialize";
document.body.appendChild(script);
}
window.onload = loadScript;