Search code examples
iosobjective-cgoogle-maps-sdk-ios

iOS Google Map SDK : Change Google Map Zoom Level with GMSCameraUpdate:fitBounds:withEdgeInsets


I want to change iOS Google Map SDK zoom level using with GMSCameraUpdate:fitBounds:withEdgeInsets. But the problem is the Google map is taking the default zoom level when i use GMSCameraUpdate:fitBounds:withEdgeInsets. Here am using withEdgeInsets to change map position. Any help will be appreciated. Below is my complete code.

GMSCoordinateBounds *markerBounds = [[GMSCoordinateBounds alloc] initWithPath:gmsPath];
GMSCameraUpdate *updatedCamera = [GMSCameraUpdate fitBounds:markerBounds withEdgeInsets:UIEdgeInsetsMake(-500, 0, 0, 0)];
[mapView_ animateWithCameraUpdate:updatedCamera];

Here gmsPath contains multiple coordinates for [GMSMutablePath path].

When i use [mapView_ animateToZoom:10]; then withEdgeInsets is not working.

I searched google and stackoverflow but i could not find correct result.


Solution

  • I found the solution with UIEdgeInsetsMake. The following is the solution.

    GMSCoordinateBounds *markerBounds = [[GMSCoordinateBounds alloc] initWithPath:gmsPath];
    GMSCameraUpdate *updatedCamera = [GMSCameraUpdate fitBounds:markerBounds withEdgeInsets:UIEdgeInsetsMake(44, 0, self.view.frame.size.height - 180, 0)];
    [mapView_ animateWithCameraUpdate:updatedCamera];
    

    -180 is the available space above UITableView