Using Google Maps' API v3, is it possible to draw a polygon on a Google maps and get a list of all the street names that fall within that polygon?

enter image description here

  • 2
    Have you tried anything? I can't see an explicit method for that, but I can think of some terrible hacks. Compute a fine grid (2m x 2m) of points over the polygon, reverse-geocode, get the street name from the response. Or use OpenStreetMap instead, and the Overpass API which (I think) can do this. – Spacedman Jul 28 '18 at 16:25
  • you can send the lat,lng of your polygon as directions like maps.googleapis.com/maps/api/directions/… – Mapperz Jul 28 '18 at 21:06

So I used the solution (OpenStreetMap) from @Spacedman:

  1. Download the .pbf for your country http://download.geofabrik.de
  2. Download the polygon file for the desired municipality from https://github.com/JamesChevalier/cities or create your polygon file (.poly) here : http://share.mapbbcode.org/
  3. Download lasted version from Osmosis https://wiki.openstreetmap.org/wiki/Osmosis#Latest_stable_version
  4. Do this:

    osmosis --read-pbf-fast you_file_country-latest.osm.pbf file="your_file_country-latest.osm.pbf" --bounding-polygon file="your_municipality_polygon.poly" --write-xml file="your_file_out.osm"

enter image description here 5. In the .osm file, you obtain all the street names, to extract the names use the option (regex) of notepad++

enter image description here

It's complex but it works, but I still have to find a way to do it directly from Google API

  • 2
    I think you should take a look at Overpass API, the following query will return all highway=* with a name in your bounding box: overpass-turbo.eu/s/AD5 ... Polygon selection would also be possible. – mmd Jul 28 '18 at 21:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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