How to get current zoom level from google map for ios?

strx86 picture strx86 · Jul 31, 2013 · Viewed 18.3k times · Source

I use method camera with digital value like this:

camera = [GMSCameraPosition cameraWithLatitude:37.35 longitude:-122.0 zoom:6];

and I need automatically redraw map with current position via timer:

-(void)gmapRedraw{
    NSLog(@"gmapRedraw");
//    self.MapView.camera
    [locationManager startUpdatingLocation];
    NSLog(@"lat %f, lon %f", locationManager.location.coordinate.latitude, locationManager.location.coordinate.longitude);
    camera = [GMSCameraPosition cameraWithLatitude:locationManager.location.coordinate.latitude//37.36//-37.81319//-33.86
                                         longitude:locationManager.location.coordinate.longitude//-122.0//144.96298//151.20
                                              zoom:6];
    self.MapView.camera = camera;
}

-(void)timer{
    [NSTimer scheduledTimerWithTimeInterval:0.5
                                     target:self
                                   selector:@selector(gmapRedraw)
                                   userInfo:nil
                                    repeats:YES];
}

but how I can get current zoom if I change it via touch?

Answer

strx86 picture strx86 · Aug 1, 2013

OK, I find solution, get current zoom:

CGFloat currentZoom = self.MapView.camera.zoom;

and then use it in camera:

camera = [GMSCameraPosition cameraWithLatitude:locationManager.location.coordinate.latitude
                                     longitude:locationManager.location.coordinate.longitude
                                          zoom:currentZoom];
self.MapView.camera = camera;