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. 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
if (status == google.maps.GeocoderStatus.OK) {
you do have an else
statment, but this isn't closed correctly. The comment // alert
also comments out the }
So you probably need to change this to
else {
// alert("Incorect adress: " +status+address);
}
instead of
else {// alert("Incorect adress: " +status+address);}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.