Configura una mappa
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Seleziona piattaforma:
Android
iOS
Per configurare una mappa per seguire un viaggio in iOS:
- Inizializzare la visualizzazione mappa
- Gestire gli eventi della mappa
Passaggio 1: inizializza la visualizzazione della mappa
Per seguire un viaggio, devi inizializzare una visualizzazione della mappa.
L'esempio seguente mostra come inizializzare 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
Passaggio 2: gestisci gli eventi della visualizzazione della mappa
Ora che hai inizializzato la visualizzazione della mappa, ecco come implementare un delegato
per gestire le modifiche agli eventi della visualizzazione della mappa man mano che il veicolo procede nel suo percorso.
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.
}
Passaggi successivi
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-09-04 UTC.
[null,null,["Ultimo aggiornamento 2025-09-04 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)"]]