A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developers.google.com/maps/documentation/ios-sdk/events below:

Events | Maps SDK for iOS

Events

Stay organized with collections Save and categorize content based on your preferences.

Using the Maps SDK for iOS, you can listen to events that occur on the map, such as camera change events or marker tap events.

Introduction

To listen to events, you must implement the GMSMapViewDelegate protocol. Typically, you implement this protocol on the view controller that displays the map. Below is an example:

Swift
import GoogleMaps

class Events: UIViewController, GMSMapViewDelegate {
  // ...
}
      
Objective-C
@import GoogleMaps;

@interface Events : UIViewController <GMSMapViewDelegate>

@end
      

When the GMSMapView is created, you can set its delegate to your view controller. The GMSMapViewDelegate provides only optional methods. To listen to any particular event, you must implement the relevant method.

Swift
override func loadView() {
  super.loadView()
  let camera = GMSCameraPosition.camera(
    withLatitude: 1.285,
    longitude: 103.848,
    zoom: 12
  )
  let mapView = GMSMapView.map(withFrame: .zero, camera: camera)
  mapView.delegate = self
  self.view = mapView
}

// MARK: GMSMapViewDelegate

func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
  print("You tapped at \(coordinate.latitude), \(coordinate.longitude)")
}
      
Objective-C
- (void)loadView {
  [super loadView];
  GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:1.285
                                                          longitude:103.848
                                                               zoom:12];
  GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
  mapView.delegate = self;
  self.view = mapView;
}

#pragma mark - GMSMapViewDelegate

- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate {
  NSLog(@"You tapped at %f,%f", coordinate.latitude, coordinate.longitude);
}
      
Camera position

Using the GMSMapViewDelegate, you can listen to changes to the camera position used to render the map. There are three distinct events.

For example, an application can clear the GMSMapView on move, and then reverse geocode the position the camera comes to rest on.

Swift
let geocoder = GMSGeocoder()

func mapView(_ mapView: GMSMapView, willMove gesture: Bool) {
  mapView.clear()
}

func mapView(_ mapView: GMSMapView, idleAt cameraPosition: GMSCameraPosition) {
    geocoder.reverseGeocodeCoordinate(cameraPosition.target) { (response, error) in
      guard error == nil else {
        return
      }

      if let result = response?.firstResult() {
        let marker = GMSMarker()
        marker.position = cameraPosition.target
        marker.title = result.lines?[0]
        marker.snippet = result.lines?[1]
        marker.map = mapView
      }
    }
  }
      
Objective-C
GMSGeocoder *geocoder;

- (void)mapView:(GMSMapView *)mapView willMove:(BOOL)gesture {
  [mapView clear];
}

- (void)mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)cameraPosition {
  id handler = ^(GMSReverseGeocodeResponse *response, NSError *error) {
    if (error != nil) {
      return;
    }
    GMSReverseGeocodeResult *result = response.firstResult;
    GMSMarker *marker = [GMSMarker markerWithPosition:cameraPosition.target];
    marker.title = result.lines[0];
    marker.snippet = result.lines[1];
    marker.map = mapView;
  };
  [geocoder reverseGeocodeCoordinate:cameraPosition.target completionHandler:handler];
}
      
Events on businesses and other points of interest

By default, points of interest (POIs) appear on the base map along with their corresponding icons. POIs include parks, schools, government buildings, and more, as well as business POIs such as shops, restaurants, and hotels.

You can respond to click events on a POI. See the guide to businesses and other points of interest.

Other events

To learn about the full list of methods on GMSMapViewDelegate, see the reference guide.

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."],[[["The Maps SDK for iOS allows you to listen to events like camera changes and marker taps by implementing the `GMSMapViewDelegate` protocol."],["You can track camera position changes using events such as `willMove`, `didChangeCameraPosition`, and `idleAtCameraPosition` to update map content dynamically."],["Respond to clicks on businesses and points of interest (POIs) using dedicated event handling mechanisms."],["Refer to the `GMSMapViewDelegate` reference for a comprehensive list of available events and methods."]]],["To listen to events on the Maps SDK for iOS, implement the `GMSMapViewDelegate` protocol in your view controller. Set the `GMSMapView`'s delegate to your view controller during creation. Implement relevant methods from the `GMSMapViewDelegate` to listen to specific events. For camera position changes, use `mapView:willMove:`, `mapView:didChangeCameraPosition:`, and `mapView:idleAtCameraPosition:`. The example provided demonstrates how to clear the map on move and reverse geocode the final camera position.\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