Configurar un mapa
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Selecciona la plataforma:
Android
iOS
Para configurar un mapa para seguir un viaje en iOS, completa los siguientes pasos:
- Inicializa la vista del mapa
- Controla eventos del mapa
Paso 1: Inicializa la vista del mapa
Para seguir un viaje, debes inicializar una vista de mapa.
En el siguiente ejemplo, se muestra cómo inicializar GMTCMapView
.
Swift
/*
* MapViewController.swift
*/
class ViewController: UIViewController, GMTCMapViewDelegate {
private var rideSharingMap: GMTCMapView?
override func viewDidLoad() {
super.viewDidLoad()
self.rideSharingMap = GMTCMapView(frame: UIScreen.main.bounds)
self.rideSharingMap.delegate = self
self.rideSharingMap?.settings.myLocationButton = true
self.view.addSubview(self.rideSharingMap!)
...
}
}
Objective-C
/*
* MapViewController.h
*/
@interface MapViewController : UIViewController<GMTCMapViewDelegate>
...
@end
/*
* MapViewController.m
*/
@implementation MapViewController
- (void)viewDidLoad {
[super viewDidLoad];
...
self.mapView = [[GMTCMapView alloc] initWithFrame:CGRectZero];
self.mapView.settings.myLocationButton = YES;
self.mapView.delegate = self;
...
}
...
@end
Paso 2: Controla los eventos de la vista de mapa
Ahora que inicializaste la vista de mapa, a continuación, se explica cómo implementar un delegado para controlar los cambios de eventos de la vista de mapa a medida que el vehículo avanza en su viaje.
Swift
func mapViewDidInitialize(_ mapview: GMTCMapView) {
// Handle the update to the state of the map view to browsing.
}
func mapView(_ mapView: GMSMapView, didTapConsumerMarker mapMarker: GMSMarker, markerType: GMTCMapViewMarkerType) -> Bool {
// Handle the mapView marker was tapped.
}
Objective‑C
/*
* MapViewController.m
*/
#pragma mark - GMTCMapViewDelegate implementation
// Handle state update of map view.
- (void)mapViewDidInitializeCustomerState:(GMTCMapView *)mapview {
// Handle the update to the state of the map view to browsing.
}
- (void)mapView:(GMSMapView *)mapView
didTapConsumerMarker:(nonnull GMSMarker *)mapMarker
markerType:(GMTCMapViewMarkerType)markerType {
// Handle the mapView marker was tapped.
}
¿Qué sigue?
Salvo que se indique lo contrario, el contenido de esta página está sujeto a la licencia Atribución 4.0 de Creative Commons, y los ejemplos de código están sujetos a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
Última actualización: 2025-08-31 (UTC)
[null,null,["Última actualización: 2025-08-31 (UTC)"],[[["\u003cp\u003eThis documentation outlines how to set up and use the Google Maps SDK for iOS to track and display trips in real-time within your application.\u003c/p\u003e\n"],["\u003cp\u003eThe guide covers initializing the map view, enabling user location, and handling events like the map becoming ready and marker taps.\u003c/p\u003e\n"],["\u003cp\u003eYou can customize the appearance of the map using styling options provided by the SDK, as well as follow a vehicle's trip progression with built-in features.\u003c/p\u003e\n"]]],["This content details how to set up a map to follow a trip in iOS. The process involves two key steps: first, initializing the map view (`GMTCMapView`) within a view controller, as demonstrated in Swift and Objective-C code examples. Second, implementing a delegate to handle map view events, which includes managing state updates and responding to marker taps. Customization of the map's style and the process to follow a trip are suggested as next steps.\n"],null,["Select platform: [Android](/maps/documentation/mobility/journey-sharing/on-demand/android/create-ui \"View this page for the Android platform docs.\") [iOS](/maps/documentation/mobility/journey-sharing/on-demand/ios/create-ui \"View this page for the iOS platform docs.\")\n\n\u003cbr /\u003e\n\nTo set up a map to follow a trip in iOS, complete the following steps:\n\n1. [Initialize the map view](#map-view)\n2. [Handle map events](#handle-updates)\n\n| **Note:** After you initialize the map view, you can customize the map. For more details, see [Style a map](/maps/documentation/mobility/journey-sharing/on-demand/ios/style).\n\nStep 1: Initialize the map view\n\nTo follow a trip, you must initialize a map view.\n\nThe following example shows how to initialize `GMTCMapView`. \n\nSwift \n\n /*\n * MapViewController.swift\n */\n class ViewController: UIViewController, GMTCMapViewDelegate {\n private var rideSharingMap: GMTCMapView?\n\n override func viewDidLoad() {\n super.viewDidLoad()\n\n self.rideSharingMap = GMTCMapView(frame: UIScreen.main.bounds)\n self.rideSharingMap.delegate = self\n self.rideSharingMap?.settings.myLocationButton = true\n self.view.addSubview(self.rideSharingMap!)\n ...\n }\n }\n\nObjective-C \n\n /*\n * MapViewController.h\n */\n @interface MapViewController : UIViewController\u003cGMTCMapViewDelegate\u003e\n ...\n @end\n\n /*\n * MapViewController.m\n */\n @implementation MapViewController\n\n - (void)viewDidLoad {\n [super viewDidLoad];\n ...\n self.mapView = [[GMTCMapView alloc] initWithFrame:CGRectZero];\n self.mapView.settings.myLocationButton = YES;\n self.mapView.delegate = self;\n ...\n }\n\n ...\n\n @end\n\nStep 2: Handle map view events\n\nNow that you've initialized the map view, here's how to implement a delegate\nto handle map view event changes as the vehicle progresses along its journey. \n\nSwift \n\n func mapViewDidInitialize(_ mapview: GMTCMapView) {\n // Handle the update to the state of the map view to browsing.\n }\n\n func mapView(_ mapView: GMSMapView, didTapConsumerMarker mapMarker: GMSMarker, markerType: GMTCMapViewMarkerType) -\u003e Bool {\n // Handle the mapView marker was tapped.\n }\n\nObjective-C \n\n /*\n * MapViewController.m\n */\n #pragma mark - GMTCMapViewDelegate implementation\n\n // Handle state update of map view.\n - (void)mapViewDidInitializeCustomerState:(GMTCMapView *)mapview {\n // Handle the update to the state of the map view to browsing.\n }\n\n - (void)mapView:(GMSMapView *)mapView\n didTapConsumerMarker:(nonnull GMSMarker *)mapMarker\n markerType:(GMTCMapViewMarkerType)markerType {\n // Handle the mapView marker was tapped.\n }\n\nWhat's next\n\n- [Style a map](/maps/documentation/mobility/journey-sharing/on-demand/ios/style)\n- [Follow a trip in iOS](/maps/documentation/mobility/journey-sharing/on-demand/ios/share-journey)"]]