问题
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