Identify the name of the streets contained in a polygon

Asked

Viewed 109 times

5

I have the following polygon below:

function initialize() {
  var bounds = new google.maps.LatLngBounds();
  var i;

  var polygonCoords = [
     new google.maps.LatLng(-23.554548, -46.607911),
     new google.maps.LatLng(-23.556043, -46.595058),
     new google.maps.LatLng(-23.564403, -46.593942),
      new google.maps.LatLng(-23.567884, -46.604757)
  ];
  

  for (i = 0; i < polygonCoords.length; i++) {
     bounds.extend(polygonCoords[i]);
  }

  var map = new google.maps.Map(document.getElementById("map_canvas2"), {
    zoom: 14,
    center: bounds.getCenter(),
    mapTypeId: "roadmap"
  });


  var sp_mooca = new google.maps.Polygon({
    paths: polygonCoords,
    strokeColor: '#0000ff',
    strokeOpacity: 0.8,
    strokeWeight: 2,
    fillColor: '#0000ff',
    fillOpacity: 0.35
  });
  sp_mooca.setMap(map);
 
  
}
#map {
  height: 100%;
}
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js"></script>

<body onload="initialize()">
  <div id="map_canvas2" style="height: 100vh; width:100vw"></div>
</body>

Is it possible to identify the names of all the streets contained in a polygon in Google Maps? If so, how?!

1 answer

0

I believe the API does not have a method that returns addresses on a polygon.

Has the containsLocation that checks if the coordinate is inside the polygon. If your intention is to extract the polygon addresses to check if it matches any address you have, you can do the opposite: check if your addresses belong to the polygon.

And has the geocode that returns the address from a coordinate. Then you can loop through coordinates within the polygon by obtaining the addresses. But this way you can reach the limit of queries easily. Code example.

I think in a way, depending on the size of the polygon, this would characterize mass extraction of the API, which is prohibited by the terms of use. You can use Openstreetmap for this, and even download the database (you can select only one region) and do the manipulations of Geodata without restrictions.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.