在 Google 地图上创建可选择/可点击的叠加层
背景目的是我想把一个国家分成不同的区域。例如,将美国分为所有州。每个状态都应该可以单击或以复选框的方式选择,以便我可以选择多个状态。所有这些都是搜索过滤器的一部分。
将一个国家/地区划分为多个地区的目的是每个地区都包含许多酒店,因此当我选择一个地区时,我会将过滤器缩小到仅该地区存在的酒店。
有没有办法使用谷歌地图来实现这一点?我很可能不会创建很多区域,因此如果唯一的方法是手动绘制线条,这是可以接受的。
如果您的解决方案与我的建议不同,请无论如何写下您的解决方案!
The background purpose is that I want to divide a country into different regions. For example, divide USA into all its states. Each state should be clickable or selectable in a checkbox way, so that I can select multiple states. All this is a part of a searching filter.
The purpose of dividing a country into regions is that each region contains for example a number of hotels, so that when I select a region, I narrow down the filter to only hotels that exist in that region.
Is there a way to accomplish this using Google Maps? Most likely I won't create very many regions, so if the only way is to draw the lines manuelly, thats acceptable.
If your solution is something else then what I'm suggestion, please write your solution anyway!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个老问题,但如果有人也遇到此类问题,我无论如何都会回答。我目前正在从事类似的任务,我必须创建可选择的道路。我想出了一个解决方案,使用包含属性、侦听器和方法的 JavaScript“类”,并在循环中使用 setMap(map) 函数将它们添加到地图画布。
基本上,这会动态创建具有可选区域的地图画布,但您仍然必须手动创建一个数据集,其中包含区域、它们的名称和其他信息以及它们的坐标边界。
我认为使用这种方法创建可选择的矩形、圆形、道路等具有悬停效果的其他对象也很容易。
伪代码:
希望这有帮助!
此致
This is an old question, but I'll answer anyways if anyone encounters this kind of problem too. I'm currently working on a similar kind of task where I have to create selectable roads. I came up with a solution by using JavaScript "classes" containing properties, listeners and methods, and adding them to map canvas with setMap(map) function in a loop.
Basically this creates the map canvas with selectable areas dynamically, but you still have to create a data set manually that contains the areas, their name and other information and their coordinate boundaries.
I think it's also easy to create selectable rectangles, circles, road etc. other objects with hover effects using this method.
Pseudocode:
Hopefully this helps!
Best regards