限制特定区域内的服务
Restrict a Service Within a Specific Area
以下是我的场景
1:首先我想定义在 3 个特定领域提供的服务。我想将这些区域保存在 mongodb 中。(我不知道是否将 1 个区域保存为一个 lat long 值或 lat long 数组)
2:我只想为那些已经提供服务的地区的用户提供服务。
关于实施此方案的任何建议以及在这种情况下哪些 google API 可以帮助我?
如本文所述, you can restrict the user's panning to a given area using the setLatLngBoundsForCameraTarget
method. Here's the documentation. Also from this post:
You can listen to the dragend
event, and if the map is dragged outside the allowed bounds, move it back inside. You can define your allowed bounds in a LatLngBounds
object and then use the contains()
method to check if the new lat/lng center is within the bounds.
You can also limit the zoom level very easily.
以下是一些可能有帮助的相关话题:
- How do I limit panning in Google maps API V3?
- Google Maps API 3 - limit pan/map bounds
以下是我的场景
1:首先我想定义在 3 个特定领域提供的服务。我想将这些区域保存在 mongodb 中。(我不知道是否将 1 个区域保存为一个 lat long 值或 lat long 数组)
2:我只想为那些已经提供服务的地区的用户提供服务。
关于实施此方案的任何建议以及在这种情况下哪些 google API 可以帮助我?
如本文所述setLatLngBoundsForCameraTarget
method. Here's the documentation. Also from this post:
You can listen to the
dragend
event, and if the map is dragged outside the allowed bounds, move it back inside. You can define your allowed bounds in aLatLngBounds
object and then use thecontains()
method to check if the new lat/lng center is within the bounds.You can also limit the zoom level very easily.
以下是一些可能有帮助的相关话题:
- How do I limit panning in Google maps API V3?
- Google Maps API 3 - limit pan/map bounds