Hi I have the following code. I would like to update my Google Maps Marker with the location given from a clicked image. Currently i have an array of images being created inside the for loop. When a user clicks on an image i would like the restMarker to update with the new longitude and latitude. Then the marker position is updated outside the loop. I can not seem to get the code below to work.
var restMarker = {
lat: 0, //Just set to a trivial value
lng: 0
};
let imagesZom = $("#zomato");
for (i = 0; i < passArrayI.length; i++) {
imagesZom.append(
$("<a>").attr("href", passArrayW[i])
.attr("target", "_blank")
.append("<img id = img" + i + " " + "src =" + passArrayI[i] + "</img>")
.click(function() {
restMarker = {
lat: parseFloat(passArrayLat[i]),
lng: parseFloat(passArrayLong[i])
};
})
)
}
setTimeout(function() {
marker.setPosition(restMarker);
map.setCenter(marker.getPosition());
}, 100)
When i run the following code it works but when i try to put it into a for loop like above i can't get it to work.
var restMarker = {
lat: parseFloat(passArrayLat[0]),
lng: parseFloat(passArrayLong[0])
};
setTimeout(function() {
marker.setPosition(restMarker);
map.setCenter(marker.getPosition());
}, 100)