州/省的地理边界 ->谷歌地图多边形
我正在构建一个 Web 应用程序,它将根据按钮和点击事件在 Google 地图上动态突出显示某些美国州和加拿大省份。
计划 A)多边形
我的主要想法是绘制多边形。为此,我需要所有州和省轮廓(顺时针或逆时针)的坐标(纬度+经度)列表。在政府网站上,我发现了各种不同的格式(即 E00),但我无法将这些格式转换为简单的坐标列表,我可以用它在地图上创建标记或多边形。您对如何获取这些坐标有什么建议吗?
计划 B)覆盖
AFAIK,如果您在 Google 地图上使用覆盖,当您进一步放大时,它们会变得像素化(或者您可以覆盖 SVG?)就我而言,在最坏的情况下我需要 50 + 11 个覆盖(所有州和所有州)省)。谷歌地图仍然可以做到这一点,还是会变得异常缓慢?
我有点惊讶没有一种直接的方法来突出显示一个州或省,因为我认为这对于使用地图 API 的人来说是一个非常常见的任务。
提前致谢
I'm building a web application that is going to dynamically highlight certain U.S. states and Canadian provinces on a Google Map, based on buttons and click events.
Plan A) Polygons
My primary idea for this was to draw Polygons. For this I need lists of coordinates (latitude + longitude) of all state and province outlines (clockwise or counter-clockwise). On government websites I found all sorts of different formats (i.e. E00), but I have trouble converting these formats into a simple list of coordinates, that I could use to create markers or a polygon on a map. Do you have any tips where to get these coordinates?
Plan B) Overlays
AFAIK, if you use overlays on Google Maps, they become pixelated as you zoom in further (or can you overlay SVGs?) In my case I would need 50 + 11 overlays in the worst-case (all states and all provinces). Is that still possible with Google Maps or will it get unsuably slow?
I'm a bit startled that there isn't a straight-forward way to highlight a state or province, as I would think this is a very common tasks for people using an API for maps.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我在此处获取了美国各州多边形的 XML。我像这个一样使用它们。
我刻意保持细节相当简单,以减少加载时间,并最终得到一张在慢速浏览器中具有合理响应能力的地图。
我没有什么可以给加拿大的。
I've got XML for US state polygons here. I use them like this.
I deliberately kept the detail fairly light to reduce the loading time and end up with a map that's reasonably responsive in slow browsers.
I don't have anything for Canada.
使用提供的 XML,我创建了一个 JSON 文件,其中包含一个字典,其中包括 50 个州、华盛顿特区和加拿大各省的粗略轮廓,以解决 SaltyNuts 的评论以及 Mike Williams 没有任何加拿大内容的注释 json。
BirdTheme 的这个方便的在线工具是我用来为任何人绘制省份多边形的工具其他人需要不同程度的细节或创建自己的坐标集。
Using the XML provided, I created a JSON file with a dictionary that includes the 50 states, Washington D.C. and a rough outline of the Canadian provinces to address SaltyNuts' comment as well as Mike Williams note of not having anything for Canada json.
This handy online tool from BirdTheme was what I used to draw the polygons for the provinces for anyone else who needs different levels of detail or to create their own set of coordinates.
老问题,但您可以从谷歌网站 https://developers.google.com/kml/documentation/us_states.kml
不过,它需要对 xml 进行一些解析。
Old question but you can get a more detailed set of points for each US state border from the google website at https://developers.google.com/kml/documentation/us_states.kml
It needs a little bit of parsing of the xml though.
这是加拿大各省的信息。
我仅从 Google 地图链接复制了第一个 GPS 坐标。
Here's the info for Canadian Provinces.
I've copied only the first GPS coordinate from the Google Map link.