I am trying to use Google's drawing tools (https://developers.google.com/maps/documentation/javascript/examples/drawing-tools), which allows me to draw on the map and get the coordinates.
Here is fiddle- https://jsfiddle.net/mg0t5x8n/2/
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 52.908978, lng: -1.451871},
zoom: 14
});
var drawingManager = new google.maps.drawing.DrawingManager({
drawingMode: google.maps.drawing.OverlayType.POLYLINE,
drawingControl: true,
drawingControlOptions: {
position: google.maps.ControlPosition.TOP_CENTER,
// drawingModes: ['marker', 'circle', 'polygon', 'polyline', 'rectangle']
drawingModes: ['polyline']
},
markerOptions: {icon: 'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png'},
circleOptions: {
fillColor: '#ffff00',
fillOpacity: 1,
strokeWeight: 5,
clickable: false,
editable: true,
zIndex: 1
}
});
drawingManager.setMap(map);
google.maps.event.addListener(drawingManager, 'polylinecomplete', function(line) {
console.log(line.getPath().getArray().toString());
alert(line.getPath().getArray().toString());
});
};
initMap();
After connecting the last line with the start of the first line you drew, you get list of coordinates. After getting these coordinates i need to run a query in the database (where i have list of locations, with lat and lon values for each) which retrieves all the locations that fall within the given points.
I'm not sure if this is possible with sql or requires something different.
Sorry if the question is bit vague, I'm at a very early stage with this and just wanted to get some info see if its possible to do and if so how i would go about it.
****** UPDATE ******
After retrieving the lat and lon value of the polygon - I came across this php function(http://assemblysys.com/php-point-in-polygon-algorithm/#comment-1243). Its sort of doing what i was after - some modification needed. Might be helpful to someone else looking to achieve something similar.