25

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?

strx86
  • 661
  • 1
  • 6
  • 8

4 Answers4

41

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;
strx86
  • 661
  • 1
  • 6
  • 8
8

If you want to detect Zoom level while user is interacting with map. We can use Google Map delegate Method

func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
    let zoom = mapView.camera.zoom
    print("map zoom is ",String(zoom))
}

Dont forgot to add GMSMapViewDelegate

Muhammad Nayab
  • 1,612
  • 14
  • 14
6

my two cents for swift 4.x:

let currZoom = self.googleMapView.camera.zoom

BUT is a Float, NOT a CGFloat, as in first objC sample. In Swift a Float is NOT a CGFloat.

ingconti
  • 10,876
  • 3
  • 61
  • 48
4

You could use animateToZoom too.

self.mapView.animateToZoom(10)
Varuna
  • 1,198
  • 1
  • 18
  • 19