Configurer une carte
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Sélectionnez une plate-forme :
Android
iOS
Pour configurer une carte afin de suivre un trajet sur iOS, procédez comme suit :
- Initialiser la vue de la carte
- Gérer les événements de carte
Étape 1 : Initialisez la vue de carte
Pour suivre un trajet, vous devez initialiser une vue de carte.
L'exemple suivant montre comment initialiser 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
Étape 2 : Gérez les événements de la vue de carte
Maintenant que vous avez initialisé la vue de carte, voici comment implémenter un délégué pour gérer les modifications d'événements de la vue de carte à mesure que le véhicule progresse dans son trajet.
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.
}
Étape suivante
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/08/31 (UTC).
[null,null,["Dernière mise à jour le 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)"]]