I'm trying to achieve some similar to Draw a polygon automatically through markers (points) in google maps but not exactly.

Given a set of locations I'd like to know if it is possible to generate the polygon container for these locations automatically. Something like what Google does with fitBounds method. But if possible, I'd like the bounds snapped to streets. For example:

Given the current set of locations:

lat: 41.87368, lon: -87.65606
lat: 41.87388, lon: -87.65452
lat: 41.87327, lon: -87.65525
lat: 41.87241, lon: -87.65636
lat: 41.87317, lon: -87.64001
lat: 41.87397, lon: -87.64186
lat: 41.87397, lon: -87.64027

my desired polygons would be:

enter image description here

The one in red and also acceptable would be a variant with the one in green.

Link to map with locations: http://bl.ocks.org/anonymous/raw/f0e736dadb07a0634b228e9ff55fcbf9/

Is this possible? I'm doing this on my backend, so my question narrows it down to available APIs that could do it. I'm currently working with OSRM, Google Maps (regular and static APIs) and OpenStreetMap.

To summarize, given a set of locations are there any APIs that would automatically generate the bounds polygon for me?

  • I think the term you are looking for is 'bounding box'. Although that won't give you something that is snapped to streets....
    – Mox
    Mar 2, 2018 at 22:51

1 Answer 1


To create a box snapped to streets, take a street layer, make the polylines into polygons. Intersect your points with those polygons; merge those blocks together. If the blocks don't connect, create centroids for your two polygons. Create a line between centroids; use that to select additional blocks. Repeat until you have a single polygon. The edges of that polygon should match streets.

  • hey, thanks for your answer and I'm sorry for the delay in getting back to you. I was traveling and for some weird reason I wasn't notified of your post. Anyway, could please elaborate? I mean, I understand your explanation but which of these tools could I use to do that? Would you be able to point me to the right direction here? Google, OSRM, OpenStreetMap? Which tools they have I could use? Thank you for your help
    – eestein
    Mar 20, 2018 at 11:07
  • I'm regret I'm only familiar with ArcMap and R. So I can only suggest a how things would work, not specific tools.
    – Mox
    Mar 20, 2018 at 19:58
  • Thanks, the thing is I can't go much further from this. I'll see what I can come up with. Thanks for your answer.
    – eestein
    Mar 20, 2018 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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