简体   繁体   English

谷歌地图第3版未显示所有标记,请协助

[英]google maps v3 not displaying all markers, please assist

I have a list of latitudes and longitudes in a report which go through GeoCode and I'm using HTML tag to display it on google map but not all markers display on the map. 我在通过GeoCode的报告中有一个经度和纬度列表,我正在使用HTML标签在Google地图上显示它,但并非所有标记都在地图上显示。 only the first few appear on the map. 只有前几个出现在地图上。

<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>

from your code I think the following line returns false at some point 从您的代码中,我认为以下行有时会返回false

if (status == google.maps.GeocoderStatus.OK) {

you do have an else statment, but this isn't closed correctly. 您确实有else陈述,但是此陈述未正确关闭。 The comment // alert also comments out the } 注释// alert还会注释掉}

So you probably need to change this to 所以您可能需要将其更改为

else {
    // alert("Incorect adress: " +status+address);
}

instead of 代替

else {// alert("Incorect adress: " +status+address);}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM