How do I get region / district polygon boundaries data from google Maps?
This data is not available from the Google Maps APIs. An alternative solution would be to use KML data, which can probably be found online, and the URL can be retrieved. This can be imported into the map using the URL using google.maps.KmlLayer
.
Anton R
Updated on November 02, 2022Comments
-
Anton R over 1 year
When I search for a region in Google Maps, for example: "Kuala Lumpur", it will show me the polygon boundary of that region.
I know that Google provide its Maps data via Google Places API. So, I query the term "Kuala Lumpur", like this: https://maps.googleapis.com/maps/api/place/autocomplete/json?input=kuala%20lumpur&types=(cities)
From that I got place ID "place_id" : "ChIJ5-rvAcdJzDERfSgcL1uO2fQ",
Then, I query the place ID to Google Places API (place details), like this: https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJ5-rvAcdJzDERfSgcL1uO2fQ
The geometry data returned only give me location coordinate and viewport:
"geometry" : { "location" : { "lat" : 3.139003, "lng" : 101.686855 }, "viewport" : { "northeast" : { "lat" : 3.245252, "lng" : 101.758509 }, "southwest" : { "lat" : 3.0327539, "lng" : 101.6152019 } } }
How do I get the complex polygon boundary points of a region?
-
Anton R over 8 yearsCan you provide me sample query to get polygon lines border for Kuala Lumpur, for instance?
-
saniokazzz about 8 yearsPlease provide example.
-
AbdealiJK over 7 yearsExample would be nice.
-
Noah Huntington about 5 yearsI think google.maps.kmlayer is only rendering an existing kml in the js api. Is there a REST equivalent using the Places API?