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];
}
}
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];
}
We have GMSCameraPosition : class that aggregates all camera position parameters
sample usage:
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.8683
longitude:151.2086
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.mapType = kGMSTypeSatellite;
we can use this camera object to set zoom level
camera.zoom = 6;
also we can re-assign camera again to map try out :)
Here is simple way to #ZoomInZoomOut byClicking on button in #iOS #GoogleMap #Swift
step1 : take command variable to manage zoom just like bellow
var currentZoom : Float = 10.0
step2 : change value of variable inside method/action of buttons
@IBAction func zoomIn(sender : UIButton)
{
self.currentZoom = self.currentZoom + 1
}
@IBAction func zoomOut(sender : UIButton)
{
self.currentZoom = self.currentZoom - 1
}
// you can also directly write mapView.animate method inside above IBAction
func zoomInZoomOutGoogleMap() {
mapView.animate(toZoom: currentZoom)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.