There is such code:
google.maps.event.addDomListener(window, 'load', function(){ var mapCanvas = document.getElementById("map-canvas"); var map = new google.maps.Map(mapCanvas, { center: new google.maps.LatLng(37.778042,-122.419136), zoom: 5, mapTypeId: google.maps.MapTypeId.TERRAIN, panControl: true }); var drawingManager = new google.maps.drawing.DrawingManager({ drawingControl: true, drawingControlOptions: { position: google.maps.ControlPosition.TOP_CENTER, drawingModes: [google.maps.drawing.OverlayType.RECTANGLE] }, drawingMode: google.maps.drawing.OverlayType.RECTANGLE }); drawingManager.setMap(map); google.maps.event.addListener(drawingManager, 'rectanglecomplete', function(rect) { var bounds = rect.getBounds(); console.log(bounds.getNorthEast().lat() + ', ' + bounds.getNorthEast().lng()); console.log(bounds.getSouthWest().lat() + ', ' + bounds.getSouthWest().lng()); }); });
Here I get the coordinates of two points of the rectangle drawn on the map. At these two points, I derive the latitude and longitude. The database stores images with coordinates. I need to compare each of them to hit a rectangle area. How is it better and easier to do? There is an idea to use the intersects method. That is something like this:
let's say we already have an array of images images and each of them has a bounds property.
for(var i = 0; i < images; i++){ if(bounds.intersects(images[i].bounds)){ console.log('match'); } }
I have not checked this code yet, but I want to know if I am going in the right direction?