S
S
Sn0wSky2015-02-06 21:56:13
JavaScript
Sn0wSky, 2015-02-06 21:56:13

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

2 answer(s)
S
Sn0wSky, 2015-02-06
@Sn0wSky

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)); 
                            }
                    );
                }

D
Dmitry Prikhodchenko, 2016-07-26
@LazyProger

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 question

Ask a Question

731 491 924 answers to any question