Google Maps API v3 - Not All Markers Showing

I am having problems with some code to display markers on a Google map. I have 8 markers defined in the code, but only 6 will show. This is the code I use, and these are the last two points in places that are not displayed.

    var locations = [


      ['', 45.382, -75.6704, 1, 'properties_detail.php?propertyID=16'], 
      ['', 45.4009, -75.7009, 1, 'properties_detail.php?propertyID=17'],    
      ['', 45.4041, -75.7017, 1, 'properties_detail.php?propertyID=18'],    
      ['', 45.4135, -75.6977, 1, 'properties_detail.php?propertyID=19'],    
      ['', 45.4176, -75.6928, 1, 'properties_detail.php?propertyID=20'],        
  ['', 45.3268, -75.8217, 1, 'properties_detail.php?propertyID=22'],    
      ['', 45.4179, -75.6928, 1, 'properties_detail.php?propertyID=23'],    
      ['', 45.3908, 75.7236, 1, 'properties_detail.php?propertyID=25']           
  ];




function initialize() {
    var mapOptions = {

      center: new google.maps.LatLng(45.392769, -75.719140),
      zoom: 11,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);

var infowindow = new google.maps.InfoWindow();

var marker, i;

var iconBase = '';



for (i = 0; i < locations.length; i++) {  

  marker = new google.maps.Marker({
    position: new google.maps.LatLng(locations[i][1], locations[i][2]),
    map: map
    ,icon: iconBase + 'tagg_map.png'
    ,url: locations[i][4]
  });

  google.maps.event.addListener(marker, 'click', function() {
        window.location.href = this.url;
   });
+3
source share
1 answer

In your test case, all 8 markers. You are missing the minus from the lng of the last point, so it goes beyond your scope, and two of them are very close (5 and 7 have the same lng), so they are displayed in the same place until you zoom in.

+1
source

All Articles