Passing Data to Callback functions?

6 views
Skip to first unread message

Numair Kaukab

unread,
Oct 17, 2016, 6:40:14 PM10/17/16
to Google Maps JavaScript API v3
var unique_interests = window.facebook_interests.filter((v, i, a) => a.indexOf(v) === i);
       
       
       
var input = map.getCenter();
       
var a = input.lat();
       
var b = input.lng();
       
       
var latlng = {lat: a, lng: b};
       
       window
.markersGP = [];
       
   
       
       
for(var i=0; i<unique_interests.length; i++)
       
{
       
       
       
var request = {
    location
: latlng,
    radius
: '500',
    query
: unique_interests[i]
 
};
       
       
       console
.log(request);
     
       service
= new google.maps.places.PlacesService(map);
       service
.textSearch(request, function (results, status){
           
           
           alert
(request.query);
       
       
           
       
});

Whenever the callback functions are called, the for loop has executed completely, and the alert() always print out the last value in the array. Is there any way to bind the data with the function call?
Reply all
Reply to author
Forward
0 new messages