javascript - Google Maps - Creating multiple markers -


i'm having bit of trouble trying loop out multiple markers onto map using information stored in array.

the code creates map no problem, it's not displaying markers i'm trying loop out...

as can see code below, there 2 functions creating markers. first using 2 values. marker displays fine.

the second function however, grabbing data array (the array has been set "squish" latitude , longitude data together, in order, google maps requires be) , not display when run.

any ideas? i'm stumped!

thanks in advance!

here's code:

initial "locations" array:

var locations = new array();  (var = 0; < data.length; i++)         {         var row = data[i];             var longitude = row[0];         var latitude = row[1];          locations[i] = latitude + longitude;         }  callmap(locations, locationfilename, userlatitude, userlongitude); 

google maps functions

    function callmap(locations, locationfilename, userlatitude, userlongitude) {   var mapoptions = {       zoom:16,       center: new google.maps.latlng(userlatitude, userlongitude),       maptypeid: google.maps.maptypeid.roadmap     };      var map = new google.maps.map(document.getelementbyid('mapview'),mapoptions);      setmarkers(map, locations, locationfilename);     currentposition(map, userlatitude, userlongitude);   }    function currentposition(map, userlatitude, userlongitude)   {    var userlatlng = new google.maps.latlng(userlatitude, userlongitude);      var marker = new google.maps.marker({         position: userlatlng,         map: map             });    }    function setmarkers(map, locations, locationfilename) {      (var = 0; < locations.length; i++) {      var markerlatlng = new google.maps.latlng(locations[i]);              var marker = new google.maps.marker({                 position: markerlatlng,                 map: map                     });      }   } 

a google.maps.latlng takes 2 numbers arguments.

this not correct:

var markerlatlng = new google.maps.latlng(locations[i]); 

this should work:

for (var = 0; < data.length; i++)     {     var row = data[i];         var longitude = row[0];     var latitude = row[1];      locations[i] = new google.maps.latlng(latitude,longitude);     } 

then

function setmarkers(map, locations, locationfilename) {    (var = 0; < locations.length; i++) {      var markerlatlng = locations[i];          var marker = new google.maps.marker({             position: markerlatlng,             map: map         });      }   } } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -