How To Highlight A State In Google Maps On Click Any Area In The State Of A Country
Solution 1:
There is no automatic API for this. You are going to have to draw a polygon either dynamically when the user clicks, or pre-draw all the U.S. State polygons in advance and hidden, then dynamically make the proper one visible when the user clicks.
As for making polygons in the shape of at least U.S. states, several persons have posted pre-defined polygon lists. One is here in StackOverflow: Geographical boundaries of states/provinces -> Google Maps Polygon
However, if you are looking at world-wide regions, states, and provinces, I doubt you will find pre-defined lists of them all. You may well have to create your own polygons by manually drawing on a Google Map or Google Earth, then export the polygon's lat/lng waypoints.
Solution 2:
recently I am creating some relative, the tests I made was based on OpenStreetMap Nominatim (https://wiki.openstreetmap.org/wiki/Nominatim), is something like:
- Click on map get Lat, Lng
- Search by reverse Geocode, get state (or city)
- Use Nominatim API to get a polygon_text (I use the geo WKT format), parse it
- Draw the polygon or polygons (if multiplygon) with Google Maps API
Hope it could make some ideas come.
Post a Comment for "How To Highlight A State In Google Maps On Click Any Area In The State Of A Country"