Adding Array of Markers in Google Map

后端 未结 3 511
南笙
南笙 2020-12-24 10:15

I need some help in creating an array of markers in Google Map so that it can be more efficient, instead of create a marker one by one. I tried the following but it doesn\'t

3条回答
  •  一整个雨季
    2020-12-24 10:47

    I see a few things:

    1) in the for loop, var pointM... should just be pointM... adding the var makes it ignore the set you have outside the for loop.

    2) you have a ; after a function that is breaking things.

    Try this:

    //create array to store a set of location
    var collection = new Array();
    
    //a set of locations stored in array
    collection[0] = new google.maps.LatLng(13.742167701649997, 100.50721049308777);
    collection[1] = new google.maps.LatLng(13.74428, 100.5404525);
    collection[2] = new google.maps.LatLng(13.744108, 100.543098);
    
    var pointMarkerImage = new Array();//store image of marker in array
    var pointMarker = new Array();//store marker in array
    
    //create number of markers based on collection.length
    function setPoint(){
      for(var i=0; i

提交回复
热议问题