Answer the question
In order to leave comments, you need to log in
Ymaps.geocode is declared and run in a loop. How to pass inside geocoder.then(); parameter unique for each iteration?
Ymaps.geocode is declared and run in a loop. How to pass inside geocoder.then(); parameter unique for each iteration?
Answer the question
In order to leave comments, you need to log in
sorry here is the code
for(var i = 0; i<hotels_num; i++){
var adr = $(".full_list li:eq("+i+")").find(".full_adr").html();
var geocoder = new ymaps.geocode(
adr,
{ results: 1 }
);
geocoder.then(
function (res) {
var name = $(".full_list li:eq(0)").html();
res.geoObjects.get(0).properties.set('balloonContentBody', name);
var coord = res.geoObjects.get(0).geometry.getCoordinates();
map.geoObjects.add(res.geoObjects.get(0));
}
);
}
It worked for me in this variant:
We take out the variable for
a = 0;
ymaps.ready(function(){
//...
//Внутри
myGeocoder.then(
console.log(a)
//мы можем производить инкремент и функция его прекрасно видит
a++;
);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question