在谷歌地图上绘制区域
如果我在谷歌地图中搜索一个查询,例如carlton victoria australia",那么它会给我一张该地区边界的地图.
If I search a query in google maps for example "carlton victoria australia" then it will give me a map of the region with the border around that area.
我的问题是:
- 有没有办法从谷歌地图api获取所有地区的列表某个省份或国家?
- 我可以合并区域信息,例如更改颜色并在区域顶部添加一些信息窗口吗?
- 我可以从 api(区、街道、村)获得什么样的区域级别?
推荐答案
目前 Google Maps JavaScript API 没有公开任何地理特征的边界.公共问题跟踪器中有一个非常古老的功能请求来添加此功能,但看起来 Google 并未对此设置高优先级:
Currently Google Maps JavaScript API doesn't expose any boundaries of geographic features. There is very old feature request in the public issue tracker to add this functionality, however it looks like Google didn't set high priority on this:
https://issuetracker.google.com/issues/35816953
请随时为公开功能请求加注星标以表达您的兴趣并订阅 Google 的进一步更新.
Feel free to star the public feature request to express your interest and subscribe to further updates from Google.
您可以从其他来源获取多边形并将它们作为附加图层添加到 Google 地图中.
You can get polygons from other sources and add them to Google maps as additional layers.
从 OpenStreetMap 获取 GeoJSON 格式的多边形的好方法在以下答案中进行了描述:
The nice workaround to get polygons in GeoJSON format from OpenStreetMap is described in the following answer:
https://stackoverflow.com/a/40172098/5140781
因此,如果您下载 GeoJSON,您将能够使用数据层及其 loadGeoJson()
方法将其添加到地图中:
So, if you download the GeoJSON you will be able to add it to map using the data layer and its loadGeoJson()
method:
https://developers.google.com/maps/documentation/javascript/datalayer#load_geojson
您可以设置 GeoJSON 对象的颜色样式并创建信息窗口.只需阅读上述文档.
You can style colors of GeoJSON objects and create info windows. Just read the aforementioned documentation.
我希望这会有所帮助!
相关文章