How can i create multiple markers on a google map?

自闭症网瘾萝莉.ら 提交于 2020-01-17 04:11:27

问题


I need to show multiple pointers based on the given latitude and longitude values.I did one sample but it comes only one pointers.As shown code below.

Meteor Js Code :

this are my objects

var latlong1 = {

      lat: 17.385044,

      long: 78.486671

    }

    console.log("* 2 *");



    var latlong2 = {

      lat: 16.306652,

      long: 80.436540

    }



    var latlong3 = {

      lat:15.505723,

      long: 80.049922

    }



    var latlong4 = {

      lat: 15.317277,

      long: 75.713888

    }

i know i can create it like this.

var marker = new google.maps.Marker({

        position: new google.maps.LatLng(lat, long),

        map: map,

        draggable: true,

        animation: google.maps.Animation.DROP,

        icon: icon

      });

and use values inside the position

new google.maps.LatLng(latlong3.lat, latlong3.long)

But there is another way?


回答1:


You should first Create an array based on that object values.

var latLong =[];

and lester create a simple function.

function createMarkers(){
  for(var i = 0 ; i <latLong.length ; i++) {
      lat = latLong[i].lat;
      long = latLong[i].long;
      var marker = new google.maps.Marker({
        position: new google.maps.LatLng(lat, long),
        map: map,
        icon: 'http://Yourimagesourcehere'
      });
    }
}

Test and tell me.



来源:https://stackoverflow.com/questions/28424854/how-can-i-create-multiple-markers-on-a-google-map

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!