Sorry if this is a basic question but I am struggling to understand how to do this.
I am trying to pass an array of passenger details through an anonymous function using the Google Places API. I am using this array details everywhere so I want to it be available in all functions. As soon as I am in the anonymous function in getDetails it looses reference to i. What I really want to do is get the value of i in displaydetails function so I can access the details there to display them in a marker.
Can anyone give me a pointer on how to do this?
Thanks in advance
var locations = [
['Mr Andrew Star', 35.776721, 140.392130, 'Tailor Made', '123456', 'ChIJVze90XnzImARoRp3YqEpbtU'],
['Miss Mary Jane', 35.684960, 139.761285, 'Group Tour', '123456', 'ChIJX1MLAgiMGGARBOTc8MbjVUU']
]
function displaydetails( place, status, image, i) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
var marker = new google.maps.Marker({
map: map,
icon: image,
position: place.geometry.location,
title: locations[i][0] //not currently working
});
....
}
}
function placeMarkers() {
for (i = 0; i < location.length; i++) {
service.getDetails({
placeId: locations[i][5]
}, function (place, status) {
displaydetails(place, status, image, i);
});
}
}