I want to create a grid that I'll be overlaying google maps. The grid has to be static, meaning 1km² grid has to be exactly at the same location and has to be identifiable with a unique id. How can I achieve this in google maps and php?
The best, redshark1802
edit: Forgot to mention that I have to interact with these grids direclty, meaning changing color/style for each field. I've found some site that did it already https://ownthisworld.com/
Get a Google Map API key. We will create a div that will display the map. We will create API wrapper in PHP that will get formatted address, latitude and longitude using the City name. We will create an Ajax request that will call the above PHP API and pass data to the google map instance.
A LatLng is a point in geographical coordinates: latitude and longitude. Latitude ranges between -90 and 90 degrees, inclusive.
The easiest way to show the coordinate grids in Google Earth is to select “Grids” from the “Tools” options. Then you will have full zoomable coordinates grid cover (Pic 1 – 3).
The answer to your question can be found in the Google Maps API (v3).
The basic approach here is:
Extended information: If you know where to draw the grid, you also know where to draw the rectangles since the edges of the rectangles are basically line segments of the grid lines. So how do you know where to draw the grid lines? If you decide on a standard zero point (for instance the point where the equator and prime Meridian meet), and basically start drawing grid lines from there, you will always have the grid lines (and thus rectangles) positioned on the same location. Note, you only draw those grid lines which are within map's view of bounds. This way it is also fairly easy to identify a rectangle by for example it's top left corner...it will always be located on the same position.
maybe these examples will help: this is a fixed size grid - position it with the NW latlng and size it using the height and width variables
this is a grid that resizes and moves to cover the map area (more or less)
both of them store the rectangles in the rectArr array, so you can manipulate their options, etc, by accessing that.
You want a quadkey. Geohash uses a similar system. You can look for a L-system to write a z curve or you can grab my code at phpclasses.org (hilbert curve). Here is good tutorial on how it works: http://blog.notdot.net/2009/11/Damn-Cool-Algorithms-Spatial-indexing-with-Quadtrees-and-Hilbert-Curves.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With