Mohammed Hussain Mohammed Hussain - 5 months ago 27
iOS Question

How to set Zoom In and Zoom out in Google ios sdk map using Button

I'm working with GoogleMaps First Time and Want to know how Should I implement a Zoom In and Zoom out on GoogleMap with the help of +/- button...
I had set The GmsCameraPosition but not clear about how to zoom in and Out Using Button...
I had To button and on there Action I'm using like below

-(void)zoomOutMapView:(id)sender


{

for (CGFloat i= 10; i<=15; i++) {


[mapView animateToZoom:i ];


[mapView setMinZoom:10 maxZoom:15];
}

}


-(void)zoomInMapView:(id)sender


{
for (CGFloat i= 10; i<=15; i--)

{
[mapView animateToZoom:i ];


[mapView setMinZoom:10 maxZoom:15];


}


}

Answer

create one common method for zoom In/Out the GmsCameraPosition and create the one common CGFloat in your viewcontroller.

for example

on your ViewDidLoad

CGFloat currentZoom = 10.0f;

create the common method like

-(Void)ZoominOutMap:(CGFloat)level
{
camera = [GMSCameraPosition cameraWithLatitude:locationManager.location.coordinate.latitude
                                 longitude:locationManager.location.coordinate.longitude
                                      zoom:level];
self.MapView.camera = camera;
}

if you press the + Button call like

-(void)zoomInMapView:(id)sender
{
 currentZoom = currentZoom + 1;

 [self ZoominOutMap:currentZoom];
}

if you press the - Button call like

-(void) zoomOutMapView:(id)sender
{
 currentZoom = currentZoom - 1;

 [self ZoominOutMap:currentZoom];
}
Comments