javascript 使用谷歌地图绘制城市/邮政编码多边形
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10525132/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
map city/zipcode polygons using google maps
提问by JZ.
I am looking for a javascript library that supports the ability to pass a zipcode or city as a parameter, and get a list of x,y coordinates to draw a polygon using google maps?
我正在寻找一个 javascript 库,它支持将邮政编码或城市作为参数传递的能力,并获取 x,y 坐标列表以使用谷歌地图绘制多边形?
Does this exist? Does the google maps API support such queries? I am looking for an array of coordinates similar to those that google uses to draw maps on a google query:
这存在吗?谷歌地图 API 是否支持此类查询?我正在寻找类似于 google 用于在 google 查询上绘制地图的坐标数组:
回答by Wojtek Szkutnik
Google Maps API doesn't support that kind of solution. There are a couple other places from which you can get the coordinates, though:
Google Maps API 不支持这种解决方案。不过,您还可以从其他几个地方获取坐标:
Flickr API
Flickr API
There is a Flickr API based on photos that people tag, but it's only as accurate as the people who tag photos: so it's good enough for bootstrapping but probably not for production: http://karya-blog.blogspot.com/2012/12/fetching-city-polygons-with-flickr-api.html
有一个基于人们标记照片的 Flickr API,但它只与标记照片的人一样准确:所以它足以用于引导但可能不适用于生产:http: //karya-blog.blogspot.com/2012/ 12/fetching-city-polygons-with-flickr-api.html
Natural Earth Data
自然地球数据
An accurate alternative is www.naturalearthdata.com. To get that data from there you just need to make two requests: one with the city name and one with their ID to get the parameters:
准确的替代方法是 www.naturalearthdata.com。要从那里获取数据,您只需要发出两个请求:一个是城市名称,另一个是他们的 ID 来获取参数:
unlock.edina.ac.uk/ws/search?name=berlin&gazetteer=naturalearth&format=json
unlock.edina.ac.uk/ws/search?name=berlin&gazetteer=naturalearth&format=json
and then
接着
unlock.edina.ac.uk/ws/footprintLookup?format=json&identifier=14126951
unlock.edina.ac.uk/ws/footprintLookup?format=json&identifier=14126951
and you're set :)
你已经准备好了:)
Mapzen
马赞
If it's possible for you to pre-fetch the data, go for Mapzen, they have a full and pretty accurate database: https://mapzen.com/data/borders/
如果您可以预取数据,请使用 Mapzen,他们有一个完整且非常准确的数据库:https://mapzen.com/data/borders/
回答by Eli Hooten
Short answer: I do not think there is any magical getZipCodeBoundaries method in the Google Maps API. However, what you want to do can and has been done. Please see the implementation, and this thread on Google groupsconcerning the process. Is the first link similar to what you're hoping to accomplish? Also, there is a neighborhood API offered from Zillow under the CC license. You might want to look into that and see if it breaks neighborhoods down by zipcode.
简短回答:我认为 Google Maps API 中没有任何神奇的 getZipCodeBoundaries 方法。但是,您想做的事情可以并且已经完成。请参阅实施,以及有关该过程的Google 群组上的此线程。第一个链接与您希望完成的内容相似吗?此外,Zillow 在 CC 许可下提供了一个社区 API。您可能想研究一下,看看它是否按邮政编码分解了社区。
回答by german_martin
You can get polygon coordenates in json for using with googlemaps using openstreetmap. Go to http://nominatim.openstreetmap.org/search a place like "Partido de Ituzaingó"
您可以在 json 中获取多边形坐标,以便使用 openstreetmap 与 googlemaps 一起使用。去http://nominatim.openstreetmap.org/搜索像“Partido de Ituzaingó”这样的地方
Steps:
脚步:
- Click on "details"
- Look for the OSM ID and copy it (control+c), example:
2018776
- Go to http://polygons.openstreetmap.fr/index.py
- Paste the ID in
- Download the polygon
- 点击“详情”
- 查找 OSM ID 并复制它(control+c),例如:
2018776
- 转到http://polygons.openstreetmap.fr/index.py
- 粘贴 ID
- 下载多边形
回答by Marcin Kostrzewa
Look on this site Twitter geo apiYou have few modes of search, and it gives You boundary box for cities. I am using it now on My site. Try f.e. this linkand U will see the results.
看看这个网站Twitter geo api你有几种搜索模式,它为你提供了城市的边界框。我现在在我的网站上使用它。试试这个链接,你会看到结果。