63

When searching Google Maps for a city, the city's administrative boundary is displayed.

enter image description here

Is there a way to get the polygon boundaries of City in a JSON format using google maps api?

55

You can get polygon coordenates in json for using with googlemaps using openstreetmap. Go to http://nominatim.openstreetmap.org/ search a place like "Partido de Ituzaing├│"

click on "details"

Look for OSM ID and copy it (control+c), example: 2018776

paste the ID in http://polygons.openstreetmap.fr/index.py and download the polygon

| improve this answer | |
24

To get polygon boundaries just add format=json to your request!

So instead of https://nominatim.openstreetmap.org/search.php?q=Warsaw+Poland&polygon_geojson=1

use

https://nominatim.openstreetmap.org/search.php?q=Warsaw+Poland&polygon_geojson=1&format=json

By adding &format=geojson you can get a valid geojson response

| improve this answer | |
7

No, there is no way to steal Google's data. May be you could look at OpenStreetMap which is designed for people to download.

| improve this answer | |
  • 1
    Have some exemple, how can extract polygons boundaries in OpenStreetMap? If I extract this, can draw the extracted polygon on google maps? – Luis Tiago Mar 4 '16 at 19:25
  • Please search this site and ask a new question if you are unable to find the answer to this – Ian Turton Mar 4 '16 at 19:52
  • 2
    Who would consider this stealing? This data is taken from the US Census. – ihodonald Jun 10 '19 at 5:17
  • 1
    then fetch it from the US census site, though I doubt they have many UK city boundaries – Ian Turton Jun 10 '19 at 7:37
7

I've found a work around solution for this problem.

  1. Go to www.gadm.org/country
  2. Choose your country and select Google Earth .kmz file format
  3. Choose the level you need (level 3 is the deepest with all small towns/cities)
  4. Download the file (can be large)
  5. Unzip the .kmz file (You'll find a .kml which is XML)
  6. Open it with Sublime or notepad++ (the file will probably be too large for other text editor)
  7. Search by city name and copy data below (Search can take 1 to 4 seconds with large file)

You can use lat,long data and parse it into an array. This solution is working well, but the quality of the path is sometimes rough.

| improve this answer | |
1

As an alternative to Google Maps API, OpenStreetMap may help you to search for a city by name in this page http://nominatim.openstreetmap.org/ . Then review search results, and you can get region coordinate in GeoJSON format e.g (http://nominatim.openstreetmap.org/details.php?place_id=145126778) to get mashhad geojson coordinates in Administrative tab

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.