Skip to content Skip to sidebar Skip to footer

How To Highlight A State In Google Maps On Click Any Area In The State Of A Country

I am willing to highlight a state in the Google maps when user click on any area in the particular state. Supprose if I click on any area in the Washington sate. Then the Washingto

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:

  1. Click on map get Lat, Lng
  2. Search by reverse Geocode, get state (or city)
  3. Use Nominatim API to get a polygon_text (I use the geo WKT format), parse it
  4. 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"