Stay organized with collections Save and categorize content based on your preferences.
The map responds to zoom gestures only when the switch is toggled on.
Get startedBefore you can try the sample code, you must configure your development environment. For more information, see Maps SDK for iOS code samples.
View the code Swiftimport GoogleMaps import UIKit class GestureControlViewController: UIViewController { private let holderHeight: CGFloat = 60 private let zoomLabelInset: CGFloat = 16 private lazy var mapView: GMSMapView = { let camera = GMSCameraPosition(latitude: -25.5605, longitude: 133.605097, zoom: 3) return GMSMapView(frame: .zero, camera: camera) }() private lazy var zoomSwitch: UISwitch = UISwitch(frame: .zero) override func viewDidLoad() { super.viewDidLoad() view.addSubview(mapView) let holder = UIView(frame: .zero) holder.backgroundColor = UIColor(white: 1, alpha: 0.8) view.addSubview(holder) let zoomLabel = UILabel(frame: .zero) zoomLabel.text = "Zoom gestures" zoomLabel.font = .boldSystemFont(ofSize: 18) holder.addSubview(zoomLabel) // Control zooming. holder.addSubview(zoomSwitch) zoomSwitch.addTarget(self, action: #selector(toggleZoom), for: .valueChanged) zoomSwitch.isOn = true [mapView, holder, zoomLabel, zoomSwitch].forEach({ $0.translatesAutoresizingMaskIntoConstraints = false }) NSLayoutConstraint.activate([ mapView.leftAnchor.constraint(equalTo: view.leftAnchor), mapView.rightAnchor.constraint(equalTo: view.rightAnchor), mapView.topAnchor.constraint(equalTo: view.topAnchor), mapView.bottomAnchor.constraint(equalTo: view.bottomAnchor), holder.heightAnchor.constraint(equalToConstant: holderHeight), holder.centerXAnchor.constraint(equalTo: view.centerXAnchor), holder.widthAnchor.constraint(equalTo: view.widthAnchor), zoomLabel.leftAnchor.constraint(equalTo: holder.leftAnchor, constant: zoomLabelInset), zoomLabel.centerYAnchor.constraint(equalTo: holder.centerYAnchor), zoomSwitch.rightAnchor.constraint(equalTo: holder.rightAnchor, constant: -zoomLabelInset), zoomSwitch.centerYAnchor.constraint( equalTo: holder.centerYAnchor), ]) NSLayoutConstraint.activate([ holder.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor) ]) } @objc func toggleZoom() { mapView.settings.zoomGestures = zoomSwitch.isOn } }Objective-C
#import "GoogleMapsDemos/Samples/GestureControlViewController.h" #import <GoogleMaps/GoogleMaps.h> @implementation GestureControlViewController { GMSMapView *_mapView; UISwitch *_zoomSwitch; } - (void)viewDidLoad { [super viewDidLoad]; GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-25.5605 longitude:133.605097 zoom:3]; _mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera]; _mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; _mapView.accessibilityIdentifier = @"gestureControlDemoMapView"; self.view = [[UIView alloc] initWithFrame:CGRectZero]; [self.view addSubview:_mapView]; UIView *holder = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 59)]; holder.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin; holder.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.8f]; [self.view addSubview:holder]; // Zoom label. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(16, 16, 200, 29)]; label.text = @"Zooming?"; label.font = [UIFont boldSystemFontOfSize:18.0f]; label.textAlignment = NSTextAlignmentLeft; label.backgroundColor = [UIColor clearColor]; label.layer.shadowColor = [[UIColor whiteColor] CGColor]; label.layer.shadowOffset = CGSizeMake(0.0f, 1.0f); label.layer.shadowOpacity = 1.0f; label.layer.shadowRadius = 0.0f; [holder addSubview:label]; // Control zooming. _zoomSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(-90, 16, 0, 0)]; _zoomSwitch.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; [_zoomSwitch addTarget:self action:@selector(didChangeZoomSwitch) forControlEvents:UIControlEventValueChanged]; _zoomSwitch.on = YES; [holder addSubview:_zoomSwitch]; } - (void)didChangeZoomSwitch { _mapView.settings.zoomGestures = _zoomSwitch.isOn; } @endRun the full sample app locally
The Maps SDK for iOS sample app is available as a download archive from GitHub. Follow these steps to install and try the Maps SDK for iOS sample app.
git clone https://github.com/googlemaps-samples/maps-sdk-for-ios-samples.git
to clone the samples repository into a local directory.Open a terminal window, navigate to the directory where you cloned the sample files, and drill down into the GoogleMaps directory:
Swiftcd maps-sdk-for-ios-samples-main/GoogleMaps-SwiftObjective-Cpod install
open GoogleMapsSwiftDemos.xcworkspace
cd maps-sdk-for-ios-samples-main/GoogleMapspod install
open GoogleMapsDemos.xcworkspace
SDKConstants.swift
file for Swift orSDKDemoAPIKey.h
file for Objective-C.SDKConstants.swift
file for Swift orSDKDemoAPIKey.h
file for Objective-C and paste your API key into the definition of either the apiKey
or kAPIKey
constant. For example: Swift
static let apiKey = "YOUR_API_KEY"Objective-C
static NSString *const kAPIKey = @"YOUR_API_KEY";
SDKConstants.swift
file (Swift) orSDKDemoAPIKey.h
file (Objective-C), remove the following line, because it's used to register the user-defined issue: Swift
#error (Register for API Key and insert here. Then delete this line.)Objective-C
#error Register for API Key and insert here.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-07-23 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-07-23 UTC."],[[["This webpage provides code samples demonstrating how to control zoom gestures on a Google Map using a switch."],["When the switch is toggled on, users can zoom in and out of the map using gestures."],["To run the sample code, you need to configure your development environment and obtain a Google Maps API key."],["The webpage provides step-by-step instructions on how to set up and run the sample app locally."]]],["The provided code demonstrates how to control zoom gestures on a Google Map in iOS using a switch. A `GMSMapView` is created, and a `UISwitch` toggles zoom gesture functionality on or off. When the switch is on, zoom gestures are enabled; when off, they are disabled. The code examples are provided in both Swift and Objective-C and include instructions on how to install the Maps SDK for iOS sample app.\n"]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4