[英]google maps v3 not displaying all markers, please assist
我在通過GeoCode的報告中有一個經度和緯度列表,我正在使用HTML標簽在Google地圖上顯示它,但並非所有標記都在地圖上顯示。 只有前幾個出現在地圖上。
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<div id="map" style="width: 700px; height: 700px"></div>
<script type="text/javascript">
var latlng = new google.maps.LatLng(40.756, -73.986);
var options = {center : latlng,zoom : 5,mapTypeId : google.maps.MapTypeId.ROADMAP};
// Creating the map
var map = new google.maps.Map(document.getElementById('map'), options);
var geocoder = new google.maps.Geocoder();
var infowindow;
function displayLocation(a) {displayMap(a, 0);}
function displayInfo(a) {displayMap(a, 1);}
function displayMap(address, displayInfo)
{geocoder.geocode( {'address' : address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker( {
map : map,
position : results[0].geometry.location});
if (!infowindow) { infowindow = new google.maps.InfoWindow();}
infowindow.setContent(address);
if (displayInfo == 1) {infowindow.open(map, marker);}
} else {// alert("Incorect adress: " +status+address);}
});
}
</script>
從您的代碼中,我認為以下行有時會返回false
if (status == google.maps.GeocoderStatus.OK) {
您確實有else
陳述,但是此陳述未正確關閉。 注釋// alert
還會注釋掉}
所以您可能需要將其更改為
else {
// alert("Incorect adress: " +status+address);
}
代替
else {// alert("Incorect adress: " +status+address);}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.