Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps API v3 - not all markers showing

Tags:

google-maps

I am having problems with some code to display markers in a Google map. I have 8 markers defined in the code, but only 6 will ever show. This is the code I am using and it's the last two items in locations that do not show.

    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;
   });
like image 321
user1110562 Avatar asked Dec 02 '25 01:12

user1110562


1 Answers

On your test case all 8 markers are there. You're missing the minus off the lng of the last point so it's plotting way off outside your scope and two of them are very close together (5 and 7 have the same lng) so appear in the same place until you zoom in.

like image 165
ChrisSwires Avatar answered Dec 04 '25 21:12

ChrisSwires



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!