Настроить карту
Оптимизируйте свои подборки
Сохраняйте и классифицируйте контент в соответствии со своими настройками.
Выберите платформу: Android iOS Чтобы настроить карту для отслеживания поездки в iOS, выполните следующие действия:
- Инициализировать вид карты
- Обработка событий карты
Шаг 1: Инициализируйте вид карты
Чтобы отслеживать поездку, необходимо инициализировать вид карты.
В следующем примере показано, как инициализировать GMTCMapView
.
Быстрый
/*
* 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
Шаг 2: Обработка событий просмотра карты
Теперь, когда вы инициализировали вид карты, вот как реализовать делегат для обработки изменений событий вида карты по мере движения транспортного средства по маршруту.
Быстрый
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.
}
Что дальше?
Если не указано иное, контент на этой странице предоставляется по лицензии Creative Commons "С указанием авторства 4.0", а примеры кода – по лицензии Apache 2.0. Подробнее об этом написано в правилах сайта. Java – это зарегистрированный товарный знак корпорации Oracle и ее аффилированных лиц.
Последнее обновление: 2025-08-29 UTC.
[null,null,["Последнее обновление: 2025-08-29 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)"]]