在Google地图的视口中显示所有街道 [英] Getting all streets visible in Google map's viewport

查看:268
本文介绍了在Google地图的视口中显示所有街道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用以下算法构建地图:


  1. 等待平移或缩放发生。

  2. 查询在视口中显示的所有街道(范围)。

  3. 使用预定义颜色为每条可见街道着色。 >

    示例:

    我想显示每条街道上的企业数量或每条街道上犯罪的数量。

    我有一个拥有这种信息(街道名,数据)的数据库,但每行都没有位置数据。

    因此,在每个地图缩放或平移后,我无法查询所有信息一个地理边界矩形,使用谷歌自己的数据库并通过街道名称查询会更有效率。

    我知道如何注册以平移和缩放事件。

    我知道如何计算视口坐标
    我知道如何为单条街道上色

    如何获得在视口中可见的所有街道列表?

    欢迎任何其他解决方案或架构。
    首选解决方案不会使用Google DirectionsService和DirectionsRenderer,因为它们减慢了地图的速度。 我的理解是,你所问的是Google API无法实现的。多边形内的反向地理编码不是他们提供的服务。其他网站上有一些帖子(例如 https://gis.stackexchange.com / questions / 22816 / how-to-reverse-geocode-without-google ),参考 gisgraphy.com 看起来像一个很漂亮的反向地理编码工具。

    然而,这仍然不能解决多边形问题中的所有街道问题。我认为你唯一的选择是让你掌握数据(开放街道地图 a>)并自己编写代码。此外 - 如果你打算为大面积做这件事,我会采取像我在这里推荐的方法: https:// stackoverflow .com / a / 18420564/1803682



    我会创建我的网格元素,并为每条街道计算它所属的所有网格并存储数据库。然后,当您搜索多边形时,您将计算多边形重叠的所有网格,然后可以在每个方格中测试道路数据的子集以确定重叠。

    我研究了这一点,并在几个月前放弃了类似的要求,并仍然希望实施它。多边形工作中的大多数点/线正在我的应用程序中创建的数据上发生(即不是街道数据),现在这是我将包含的唯一数据。我想说的是 - 我希望有人给你一个更好的答案。

    更新:



    对于您所问的问题,我仍然相信您会需要使用基于OpenStreetMap的自己的数据库组合和事先进行的某种网格分析。如果你有一些时间来承担这个项目,这个应该不会太难处理。数据库将很大,所需的计算可能需要大量的一次/前期处理时间。至于突出显示视口内的路线/道路/任何东西,有很多方法可以使用API​​来实现这一点 - 这里我发现有用的示例:使用google maps api v3的多段线路对齐道路



    同样有用:< a href =http://econym.org.uk/gmap/snap.htm =nofollow noreferrer> http://econym.org.uk/gmap/snap.htm



    请注意,如果使用方向api捕捉街道,单向街道可能会带来一些悲伤,您可能必须注意这一点并纠正或反转开始/结束点。 / p>

    I'm trying to build a map with the following algorithm:

    1. Wait for pan or zoom to occurs.
    2. Query for all streets visible in the viewport (extent).
    3. Color every visible street with a predefined color.

    Example:
    I want to show the numbers of businesses on each street, or the number of crimes committed at each street.
    I have a DB which holds this kind of information (streetname, data), but each row doesn't have the location data.
    Therefore, after each map zoom or pan, I cannot query all of it by a geographical bounding rectangle, it will be far more efficient to use Google own DB and query it by street names.

    I know how to register to pan and zoom events.
    I know how to calculate the viewport coordinates.
    I know how to color a single street.

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

    解决方案

    My understanding is that what you are asking is not possible from Google API's. Reverse geocoding inside a polygon is not a service they offer. There are some posts on other sites (e.g. https://gis.stackexchange.com/questions/22816/how-to-reverse-geocode-without-google) with the reference gisgraphy.com looking like a pretty neat reverse geocoding tool.

    This still does not address your all streets in a polygon problem however. I think your only option would be to get your hands on the data (Open Street Maps) and write the code yourself. Further - if you are going to do this for a large area I would take an approach like I recommended here with grids: https://stackoverflow.com/a/18420564/1803682

    I would create my grid elements, and for each street calculate all the grids to which it belongs and store in the database. Then when you search a polygon, you would calculate all the grids the polygon overlaps, and can then test the subset of road data in each of those squares to determine overlap.

    I looked into this and abandoned a similar requirement a few months back and still have a desire to implement it. Most of the point/line in polygon work is happening on data created in my application (i.e. not street data) and right now that is the only data I will be including. What I am trying to say is - I hope someone gives you a better answer.

    Update:

    For what you are asking I still believe you will need to use a mix of your own database based on OpenStreetMap and some kind of grid analysis carried out in advance. If you have some time to commit to the project this should not be too awful to process. The database will be large, and the calculations needed will likely require a significant amount of one-time / upfront processing time. As far as highlighting routes/roads/whatever within the viewport, there are lots of way to accomplish this using the API - example here which I found useful: polyline snap to road using google maps api v3

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

    Note that one way streets may give some grief if using the directions api to snap to a street and you will likely have to watch for this and correct or reverse the start/end points.

    这篇关于在Google地图的视口中显示所有街道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆