Display all streets in the Google Map Viewer

I am trying to build a map with the following algorithm:

  • Wait for the pan or zoom to happen.
  • Request for all streets visible in the viewport (size).
  • The color of each visible street with a predefined color.

Example:
I want to show the number of businesses on each street or the number of crimes committed on each street.
I have a database that contains such information (street name, data), but each row does not have location data.
Therefore, after each map zooming or panning, I can’t query all this with the help of a geographic bounding box, it will be much more efficient to use my own Google DBMS and query it by street names.

I know how to log in to pan and zoom events.
I know how to calculate viewport coordinates .
I know how to color one street .

How can I get a list of all the streets visible in the viewport?
Any other solutions or architectures are welcome. The preferred solution will not use Google DirectionsService and DirectionsRenderer, as they slow down the map.

+4
source share
2 answers

I understand that what you ask for is not possible from the Google API. Reverse geocoding inside a polygon is not a service that they offer. There are several posts on other sites (e.g. https://gis.stackexchange.com/questions/22816/how-to-reverse-geocode-without-google ) with a gisgraphy.com link looks like a pretty neat reverse geocoding tool.

However, this still does not apply to all of your streets in the polygon problem. I think your only option is to get your data ( Open Street Maps ) and write the code yourself. Next - if you are going to do this for a large area, I would suggest an approach like I recommended here with grids: fooobar.com/questions/1480215 / ...

I would create grid elements, and for each street I calculated all the grids to which it belongs and store them in a database. Then, when you perform a polygon search, you compute all the grids that overlap the polygons, and then can test a subset of the road data in each of these squares to determine the overlap.

I reviewed this and rejected a similar requirement a few months ago and still want to implement it. Most of the points / lines in the polygon work on the data created in my application (i.e. not on the streets), and now this is the only data that I will include. What I'm trying to say is I hope someone gives you a better answer.

Update:

For what you ask, I still think that you will need to use a combination of your own OpenStreetMap-based database and some kind of grid analysis done in advance. If you have time to complete a project, this should not be too terrible to process. The database will be large and required calculations will require a significant amount of one-time / pre-processing time. Regarding the allocation of routes / roads / regardless of the viewing area, there are many ways to do this using the API example that I found useful: the polyline is attached to the road using google api v3 maps

Also useful: http://econym.org.uk/gmap/snap.htm

Note that one-way streets can give some grief if you use the api directions to click on the street, and you may have to keep track of this and correct or discard the start / end points.

0
source

Google recommends using the geocoding service to populate the database with coordinates. You can then use the LatLng Bounds Class method to check if your points are in the viewport. The advantage of this approach is that you only need to geocode the information once and then save it, as well as send encoding requests every time the viewport changes.

An alternative effective way to display such data would be to use Google's merge tables. this greatly simplifies data integration with the card.

-1
source

Source: https://habr.com/ru/post/1480212/


All Articles