Answer the question
In order to leave comments, you need to log in
How to arrange dynamically Multiple addresses on the map?
All the best!
Is there a code example of how you can arrange several addresses on the map, having only a few addresses on hand?
That is, I have an AJAX request that sends me a list of several addresses in JSON format (I can send it in any format):
["г.Томск, Учебная улица 15","г.Томск, Карповский переулок 15","г.Томск, проспект Кирова 48"]
ymaps.ready(init);
var myMap;
function init(){
myMap = new ymaps.Map("map", {
center: [56.49540919, 84.95061710],
zoom: 12,
controls: ['zoomControl']
});
var coords = [
[56.458592, 84.947361],
[56.49844, 84.950236]
];
for (var i = 0; i < coords.length; i++) {
myMap.geoObjects.add(new ymaps.Placemark(coords[i]));
}
myMap.setBounds(myMap.geoObjects.getBounds());
}
$("body").on("click", '#reload', function() {
var newCoords = [
[56.510298, 85.029584],
[56.475678, 85.008743]
]
myMap.geoObjects.removeAll();
for (var i = 0; i < newCoords.length; i++) {
myMap.geoObjects.add(new ymaps.Placemark(newCoords[i]));
}
myMap.setBounds(myMap.geoObjects.getBounds());
});
Answer the question
In order to leave comments, you need to log in
var q = ymaps.geoQuery();
data.forEach(function (address) {
q.add(ymaps.geocode(address));
});
q.addToMap(map);
https://tech.yandex.ru/maps/doc/jsapi/2.1/dg/conce...
But in general, geocoding arrays of addresses on the client is a bad practice, read habrahabr.ru/company/yandex/blog/263863
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question