Khởi chạy SDK người tiêu dùng
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Để bắt đầu chia sẻ hành trình từ Fleet Engine và phụ trợ của khách hàng, bạn cần khởi chạy Consumer SDK trong ứng dụng iOS.
providerID
giống với Mã dự án của Dự án trên Google Cloud. Để biết thông tin về cách thiết lập Dự án Google Cloud, hãy xem phần Tạo dự án Fleet Engine.
Các ví dụ sau đây cho thấy cách khởi chạy Consumer SDK trong ứng dụng của bạn.
Swift
/*
* AppDelegate.swift
*/
import GoogleRidesharingConsumer
import GoogleMaps
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Register your API key for GMSServices.
GMSServices.provideAPIKey(yourMapsAPIKey)
// Set the instance of the SampleAccessTokenProvider.
GMTCServices.setAccessTokenProvider(SampleAccessTokenProvider(), providerID: yourProviderID)
// Other initialization code ...
return true
}
}
Objective-C
/*
* AppDelegate.m
*/
#import <GoogleMaps/GoogleMaps.h>
#import <GoogleRidesharingConsumer/GoogleRidesharingConsumer.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//Register your API key for GMSServices.
[GMSServices provideAPIKey:yourMapsAPIKey];
//Set the instance of the AccessTokenFactory.
[GMTCServices setAccessTokenProvider:[[SampleAccessTokenProvider alloc] init]
providerID:yourProviderID];
// Other initialization code ...
return YES;
}
@end
Tiếp theo là gì?
Thiết lập bản đồ
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-31 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-31 UTC."],[[["\u003cp\u003eTo share journeys from Fleet Engine and your backend, you must initialize the Consumer SDK in your iOS application using your Google Cloud Project ID (\u003ccode\u003eproviderID\u003c/code\u003e) and API key.\u003c/p\u003e\n"],["\u003cp\u003eThe provided Swift and Objective-C code snippets demonstrate how to initialize the SDK within your app's AppDelegate.\u003c/p\u003e\n"],["\u003cp\u003eAfter initializing the SDK, you can proceed with setting up a map to display journey information using the provided documentation link.\u003c/p\u003e\n"]]],[],null,["To start sharing journeys from Fleet Engine and the customer backend,\nyou need to initialize the Consumer SDK in your iOS application.\n\nThe `providerID` is the same as the **Project ID** of your Google Cloud\nProject. For information on setting up the Google Cloud Project, see\n[Create your Fleet Engine project](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/create-project).\n\nThe following examples show how to initialize the Consumer SDK in your app. \n\nSwift \n\n /*\n * AppDelegate.swift\n */\n import GoogleRidesharingConsumer\n import GoogleMaps\n\n @UIApplicationMain\n class AppDelegate: UIResponder, UIApplicationDelegate {\n\n func application(_ application: UIApplication,\n didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -\u003e Bool {\n\n // Register your API key for GMSServices.\n\n GMSServices.provideAPIKey(yourMapsAPIKey)\n\n // Set the instance of the SampleAccessTokenProvider.\n\n GMTCServices.setAccessTokenProvider(SampleAccessTokenProvider(), providerID: yourProviderID)\n\n // Other initialization code ...\n\n return true\n }\n }\n\nObjective-C \n\n /*\n * AppDelegate.m\n */\n #import \u003cGoogleMaps/GoogleMaps.h\u003e\n #import \u003cGoogleRidesharingConsumer/GoogleRidesharingConsumer.h\u003e\n\n @implementation AppDelegate\n\n - (BOOL)application:(UIApplication *)application\n didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\n //Register your API key for GMSServices.\n [GMSServices provideAPIKey:yourMapsAPIKey];\n\n //Set the instance of the AccessTokenFactory.\n [GMTCServices setAccessTokenProvider:[[SampleAccessTokenProvider alloc] init]\n providerID:yourProviderID];\n\n // Other initialization code ...\n return YES;\n }\n\n @end\n\nWhat's Next\n\n[Set up a map](/maps/documentation/mobility/journey-sharing/on-demand/ios/create-ui)"]]