javascript 在 Google Map API 中创建邮政编码边界

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11471497/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 13:20:57  来源:igfitidea点击:

Make Zip code boundaries in Google Map API

javascriptgoogle-mapsgoogle-maps-api-3zipcode

提问by njavia66

I have seen all the responses to a similar question, however, they are all either old, or no one has answered them.

类似问题的所有回答我都看过了,要么都是旧的,要么没人回答。

I have been given the task to obtain zip codes and display their corresponding boundaries to the user on a Google map, like in this example.

我的任务是获取邮政编码并在谷歌地图上向用户显示它们对应的边界,就像在这个例子中一样

I am writing this code in Javascript and using the Google Maps API. I want the user to input a zip code and a marker drops down on their destination with a border representing that zip code area. I see that Google Maps currently has something in their map code that allows one to see the boundaries if someone puts a zip code on maps.google.com. I have used polygons but this wouldn't help make a border around a certain zip code.

我正在用 Javascript 编写此代码并使用 Google Maps API。我希望用户输入一个邮政编码,然后在他们的目的地上下拉一个标记,并带有一个代表该邮政编码区域的边框。我看到谷歌地图目前在他们的地图代码中有一些东西,如果有人在 maps.google.com 上输入邮政编码,它允许人们看到边界。我使用了多边形,但这无助于在某个邮政编码周围制作边框。

Any suggestions on how to obtain this?

关于如何获得这个的任何建议?

Thanks in advance!

提前致谢!

采纳答案by Mark

There is not an easy answer to this that I know of. But here is a high level design of how to do it.

据我所知,对此没有一个简单的答案。但这里是如何做到这一点的高级设计。

All of the shape files for zip codes can be found at the census site and can be downloaded from this ftp server. However, that's a ton of data, so you need a place to store it. I recommend using the PostgreSQL database with the PostGIS add on. It is free and open source and generally awesome. It has a utility for converting .shp files (the type in the census shape files) into PostGIS geometry form. PostGIS let's you retrieve the shapes back out as KML.

所有邮政编码的形状文件都可以在人口普查站点上找到,也可以从这个 ftp 服务器下载。但是,这是大量数据,因此您需要一个地方来存储它。我建议使用带有 PostGIS 插件的 PostgreSQL 数据库。它是免费和开源的,而且通常很棒。它具有将 .shp 文件(人口普查形状文件中的类型)转换为 PostGIS 几何形式的实用程序。PostGIS 让您将形状检索为 KML。

You can either a) retrieve a shape from the database as KML when it is needed and display it on the map or b) pre-generate a kml file for every zip code ahead of time and retrieve a file as it is needed (this would take up quite a bit of space).

您可以 a) 在需要时从数据库中检索形状作为 KML 并将其显示在地图上或 b) 提前为每个邮政编码预先生成一个 kml 文件并在需要时检索一个文件(这将占用相当多的空间)。

回答by lazaruslarue

You need to become familiar with GeoJSON formatted FeatureCollections. You can render them on any set of map tiles with OpenLayers (or probably Google API as well)

您需要熟悉 GeoJSON 格式的 FeatureCollections。您可以使用 OpenLayers(或者也可能是 Google API)在任何一组地图图块上渲染它们

This may seem pretty hard, but is totally approachable.

这可能看起来很难,但完全平易近人。

You can purchase GeoJSON files for groups of Zipcodes if you search around.

如果您四处搜索,您可以为邮政编码组购买 GeoJSON 文件。