4

I have two coordinates, and I need to restrict my Google Maps map to the frame bounded by those two coordinates. For example, I have

let bounds = GMSCoordinateBounds(
    coordinate: CLLocationCoordinate2D(
        latitude: 59.615440364671244, 
        longitude: -17.978949286043644
    ), coordinate: CLLocationCoordinate2D(
        latitude: 33.963318167747758, 
        longitude: 21.442294009029865
    )
)

Then, I write,

map.cameraTargetBounds = bounds

However, this does nothing to restrict the bounds of the map while it should. According to the documentation,

If not nil, [cameraTargetBounds] constrains the camera target so that gestures cannot cause it to leave the specified bounds.

This question did not help me, partially because I must allow zooming as well as panning––it just must be restricted to a certain area.

Why is this not working, and how can I fix it?

IHaveAQuestion
  • 789
  • 8
  • 26

1 Answers1

0

You have to use GoogleFletcher. In this we will implement two filters (GMSCoordinateBound and Type). In start bound cordinate we will put current location and at end bound we will just add 1 in our current location cordinates. Hopefully it helps.

let location = locations.last!
let neBoundsCorner = CLLocationCoordinate2D(latitude:location.coordinate.latitude,
                   longitude: location.coordinate.longitude)
let swBoundsCorner = CLLocationCoordinate2D(latitude: location.coordinate.latitude + 1, longitude: location.coordinate.longitude + 1)
let bounds = GMSCoordinateBounds(coordinate: neBoundsCorner,coordinate: swBoundsCorner)
let filter = GMSAutocompleteFilter()
    filter.type = .establishment 
    fetcher = GMSAutocompleteFetcher(bounds: bounds, filter: filter)
Zain Shahzad
  • 74
  • 1
  • 4