0

I am loading a Google Place from the autocomplete API then looking up place details to zoom in on my map.

I have a GMSMapView defined in my XIB which I can see when I run my view controller.

Originally the zoom level is at 4. When I set the coordinate and zoom level, it stays zoomed out despite my debugger saying the zoom level is 2.

How do I zoom in?

(lldb) po self.map
<GMSMapView: 0x7f8c62a9ebc0; frame = (0 73.3333; 414 576.667); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7f8c67029fc0>; layer = <GMSMapLayer: 0x7f8c62a57aa0>>

(lldb) po self.map.camera
GMSCameraPosition 0x7f8c62d2d030: target:(29.741, -95.374) bearing:0.000 zoomLevel:2.000 viewingAngle:0.000


- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupButtons];

    self.map.delegate = self;

    self.client = [GMSPlacesClient sharedClient];
    [self.client lookUpPlaceID:self.prediction.placeID callback:^(GMSPlace * _Nullable result, NSError * _Nullable error) {
        [self showResult:result];
    }];
}

- (void)showResult:(GMSPlace *)place {
    self.place = place;

GMSCameraPosition *position = [[GMSCameraPosition alloc] initWithTarget:place.coordinate zoom:0.2 bearing:0 viewingAngle:0];
    [self.map setCamera:position];
    [self.map animateWithCameraUpdate:[GMSCameraUpdate setTarget:place.coordinate zoom: 0.15]];   

    [self.map moveCamera:[GMSCameraUpdate setTarget:place.coordinate zoom: 0.15]];
}
quantumpotato
  • 9,637
  • 14
  • 70
  • 146

2 Answers2

0

You can set the zoom programmatically with animateToZoom: on GMSMapView.

Sample codes are shown below:

Objective-C

[mapView_ animateToZoom:12];

Swift

mapView.animateToZoom(12)

Aside from that, you can also restrict the range of zoom available to the map by setting a min and max zoom level. The zoom range must be set using the setMinZoom:maxZoom: method, however the values can be read individually using the minZoom and maxZoom properties. This is helpful when restricting only one of the values.

You may find sample codes in the given documentation and you may also use GMSMapView Class Reference for the other methods related to the map.

And, this SO post - GMSMapView animateToCameraPosition zoom in - zoom out animation might also help.

Community
  • 1
  • 1
Teyam
  • 7,686
  • 3
  • 15
  • 22
0

I guess you are doing something wrong here. You said that

Originally the zoom level is at 4. When I set the coordinate and zoom level, it stays zoomed out despite my debugger saying the zoom level is 2.

Just to be clear, zoom level 4 is > zoom level 2. If you want your map to be zoomed in try using higher values i.e. around 15, 16 etc.

Hope it helps.

Bharat
  • 340
  • 1
  • 8