I have a map with 5 markers and 25 rectangles. Then I drag the marker to a rectangle I want to know the title of the rectangle.
Right now I have a listener to the rectangles, just for seeing that they is named correctly and this works fine
google.maps.event.addListener(partialRectangle, 'click', function() {
console.log(this.title);
});
and I also have a listner to the markers to get some information then dragging them and that´s works fine too
google.maps.event.addListener(marker, 'dragend', function() {
console.log(marker.getPosition());
console.log(this.title);
});
Any idea how to get out the info about in which rectangle I dropped the markers?
This code solved my problems
google.maps.event.addListener(marker, 'dragend', function() {
for(var i = 0; i < 25; i++){ // looping through rectangles
if(partialRectangles[i].bounds.contains(marker.getPosition()))
console.log(partialRectangles[i].title);
}
});
Within each marker’s
dragendlistener, loop through all the rectangle’sLatLngBoundsand use thecontains(latLng:LatLng)function to determine if the new marker’s position is inside that rectangle’sLatLngBounds.Pseudo-code: