Answer the question
In order to leave comments, you need to log in
How to set the starting position for a map from a set of addresses in the Google maps API?
Friends, I really need help, I broke my whole head, there is a Google map, with an array of addresses:
var locations = [
['Москва, Россия', 'Москва', 'infowindow 1'],
['Барнаул, Россия', 'Барнаул', 'infowindow 2'],
['Улан-Удэ, Россия', 'Улан-Удэ', 'infowindow 3']
];
Answer the question
In order to leave comments, you need to log in
We throw a flag into the geocoder function, for which address we set the center of the map
for (var i = 0; i < locations.length; i++) {
geocodeAddress(locations[i], i == 0);
}
function geocodeAddress(location, isSetToCenterMap) {
geo.geocode({'address' : location[0]}, function (results,status) {
if(status == google.maps.GeocoderStatus.OK) {
if (isSetToCenterMap) {
map.setCenter(results[0].geometry.location);
}
createMarker(results[0].geometry.location,location[0],location[1],location[2]);
}
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question