初始化使用方 SDK
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
如需开始从 Fleet Engine 和客户后端分享行程,您需要在 iOS 应用中初始化 Consumer SDK。
providerID
与您的 Google Cloud 项目的项目 ID 相同。如需了解如何设置 Google Cloud 项目,请参阅创建 Fleet Engine 项目。
以下示例展示了如何在应用中初始化 Consumer SDK。
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
后续步骤
设置地图
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\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)"]]