Search code examples
mongodbgoogle-mapsgoogle-maps-api-3geofencinglocation-aware

Restrict a Service Within a Specific Area


Following is my scenario

1: First i want to define a service offered in 3 particular areas. I want to save those areas in mongodb.(i don't know whether 1 area would be saved as one lat long value or an array of lat long )

2: i want to offer the service only to those users who exist in those areas where service has been offered.

Any suggestions for implementing this scenario and what google APIs would help me in this case?


Solution

  • As stated in this thread, 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.

    Here are some related threads which might help: