Inicjowanie pakietu SDK klienta
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Aby zacząć udostępniać podróże z Fleet Engine i backendu klienta, musisz zainicjować pakiet Consumer SDK w aplikacji na iOS.
Wartość providerID
jest taka sama jak Identyfikator projektu w Twoim projekcie Google Cloud. Informacje o konfigurowaniu projektu Google Cloud znajdziesz w artykule Tworzenie projektu Fleet Engine.
Poniższe przykłady pokazują, jak zainicjować pakiet SDK dla konsumentów w aplikacji.
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
Co dalej
Konfigurowanie mapy
O ile nie stwierdzono inaczej, treść tej strony jest objęta licencją Creative Commons – uznanie autorstwa 4.0, a fragmenty kodu są dostępne na licencji Apache 2.0. Szczegółowe informacje na ten temat zawierają zasady dotyczące witryny Google Developers. Java jest zastrzeżonym znakiem towarowym firmy Oracle i jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-08-31 UTC.
[null,null,["Ostatnia aktualizacja: 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)"]]