I want to know if this is possible with google maps. I create a 2 small grids on google maps with kml file.
How can I find out using php of if my address is listed in grid 1 or 2. Need help please.
I want to know if this is possible with google maps. I create a 2 small grids on google maps with kml file.
How can I find out using php of if my address is listed in grid 1 or 2. Need help please.
I wrote code for doing exactly this, but rather than grids, for areas of the UK.
I had to read the KML file like XML using
DOMDocument::load()
, this enables you to read the KML file and get the longitude and latitude points it contains. Bear in mind though that I had to change the KML slightly for this to work. Firstly after building your custom map in Google Maps right click and copy the Google Earth link - this will give something like thisYou should change the output to
kml
, visit then save the output, I have ommitted part of this URL here as not to give away my map!I then had to remove the
<kml>
element be removing the following linesAnd
This will leave you with just the
<Document>
element which contains the point. You then read this using DOMDocument and iterate over it to get the coordinates it contains. For example you can then iterate over the Placemarks and their coordinates, creating a polygin and then intersecting that with the long. I used this site for the polygon code http://www.assemblysys.com/dataServices/php_pointinpolygon.php . It is a Util class in this example: