How To Delete Ride Sharing Services On Maps App
You can use the Consumer SDK to build and run a basic consumer app integrated with On-demand Rides and Deliveries Solution backend services. You tin can create a Trip and Order Progress app that can brandish an agile trip, respond to trip updates, and handle trip errors.
Because the Consumer SDK has a modular compages, yous can use the parts of the API that you want to apply for your particular app and integrate them with your own APIs, backend services provided by the Fleet Engine, and improver API's of the Google Maps Platform.
Prerequisites
Transportation and Logistics Android SDKs are published to an Artifact Registry Maven repository. The repository includes the SDK'due south Projection Object Model (.pom) files and offline Javadocs.
Get Admission
If you are a Google Workspace client, create a Workspace Group such as google-maps-platform-sdk-users@workspacedomain.com during onboarding and provide the name to Google. This is the recommended approach. Your Workspace Grouping volition and so be added to an allowlist that grants admission to the Maven repository gmp-artifacts/transportation. Confirm that the user emails and service account emails that need access are included in this list.
If your organization cannot create Workspace Groups, send to Google a listing of user and service business relationship emails that need access to these artifacts.
Local Development
For local development, it is sufficient to log in with the Cloud SDK.
The email used to log in must be a fellow member of the Workspace Grouping.
Automation (Build Systems or Continuous Integration)
Set your automation hosts co-ordinate to best practices:
-
If your process runs inside a Google Cloud environs, use automatic credential detection.
-
Otherwise, store the service account key file in a secure location on the host's file-system and ready the GOOGLE_APPLICATION_CREDENTIALS environment variable accordingly.
The service account email associated with the credentials must exist a fellow member of the Workspace Goup.
Configuration
Configure Maven or Gradle to find user or service credentials automatically.
Gradle
Add the following to your app module's build.gradle file, non the projection root module build.gradle file:
plugins { id "com.google.cloud.artifactregistry.gradle-plugin" version "2.i.five" } repositories { maven { url "artifactregistry://us-west2-maven.pkg.dev/gmp-artifacts/transportation" } } Maven
Add together the post-obit to your pom.xml:
<repositories> <repository> <id>gmp-artifacts</id> <url>artifactregistry://united states of america-west2-maven.pkg.dev/gmp-artifacts/transportation</url> <releases> <enabled>true</enabled> </releases> </repository> </repositories> <build> <extensions> <extension> <groupId>com.google.cloud.artifactregistry</groupId> <artifactId>artifactregistry-maven-railroad vehicle</artifactId> <version>two.1.0</version> </extension> </extensions> </build> For information on verifying access, see Managing Java packages.
Project Configuration
To use the Consumer SDK for Android, your app must target minSdkVersion nineteen or higher.
To run an app built with the Consumer SDK, the Android device must accept Google Play services installed.
Set upwardly your evolution project
To set up your development project and get an API key for the project on the Google Deject Console:
-
Create a new Google Cloud Console projection, or select an existing project, for use with the Consumer SDK. Wait a few minutes until the new projection is visible on the Google Cloud Panel.
-
In society to run the demo app, your project must accept access to the Maps SDK for Android. In the Google Cloud Console, select APIs & Services > Library, then search for and enable the Maps SDK for Android.
-
Go an API key for the projection past selecting APIs & Services > Credentials > Create credentials > API key. For more than information about getting an API key, see Get an API fundamental.
Add the Consumer SDK to your app
The Consumer SDK is available via a private Maven repository. The repository includes the SDK'due south Project Object Model (.pom) files and Javadocs. To add the Consumer SDK to your app:
-
Fix your environment to admission the host Maven repository equally described in Get Access.
If you lot have centralized dependency management configuration declared in
settings.gradle, disable it equally follows.-
Remove the following code cake in
settings.gradle:import org.gradle.api.initialization.resolve.RepositoriesMode dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() } }
-
-
Add the following dependency to your Gradle or Maven configuration, substituting the
VERSION_NUMBERplaceholder for the desired version of the Consumer SDK.Gradle
Add the following to your
build.gradle:dependencies { ... implementation 'com.google.android.libraries.mapsplatform.transportation:transportation-consumer:VERSION_NUMBER' }Maven
Add the following to your
pom.xml:<dependencies> ... <dependency> <groupId>com.google.android.libraries.mapsplatform.transportation</groupId> <artifactId>transportation-consumer</artifactId> <version>VERSION_NUMBER</version> </dependency> </dependencies>
Add the API key to your app
Once y'all accept added the Consumer SDK to your app, add the API key to your app. You must apply the project API key y'all obtained when yous ready your development project.
This department describes how to store your API key so that it can be more deeply referenced by your app. Y'all should not check your API key into your version control system. It should be stored in the local.properties file, which is located in the root directory of your projection. For more information nearly the local.properties file, run across Gradle properties files.
To streamline this task, you can use the Secrets Gradle Plugin for Android.
To install the plugin and shop your API fundamental:
-
Open up your root-level
build.gradlefile and add the following lawmaking to thedependencieschemical element underbuildscript.Slap-up
buildscript { dependencies { // ... classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:two.0.0" } }Kotlin
buildscript { dependencies { // ... classpath("com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.0") } } -
Open your app-level
build.gradlefile and add the following code to thepluginselement.Bang-up
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'Kotlin
id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin") -
If you employ Android Studio, sync your projection with Gradle.
-
Open the
local.propertiesin your project level directory, and then add the following code. ReplaceYOUR_API_KEYwith your API central.MAPS_API_KEY=YOUR_API_KEY -
In your
AndroidManifest.xmlfile, go tocom.google.android.geo.API_KEYand update theandroid:valueattribute as follows:<meta-data android:proper name="com.google.android.geo.API_KEY" android:value="${MAPS_API_KEY}" />
The following example shows a consummate manifest for a sample app:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.consumerapidemo"> <uses-permission android:proper name="android.permission.ACCESS_FINE_LOCATION" /> <application android:allowBackup="truthful" android:icon="@mipmap/ic_launcher" android:characterization="@string/app_name" android:supportsRtl="truthful" android:theme="@fashion/_AppTheme"> <meta-information android:name="com.google.android.geo.API_KEY" android:value="${MAPS_API_KEY}" /> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> Include the required attributions in your app
If y'all use the Consumer SDK in your app, you must include attribution text and open source licenses as part of your app's legal notices section. It'due south best to include the attributions as an independent carte item or every bit role of an About menu item.
You tin can find the required attribution text and open up source licenses in the Ridesharing Consumer SDK zip file:
-
Detect.txt -
LICENSES.txt
Consumer SDK Authentication
The Consumer SDK provides hallmark using JSON Web Tokens. A JSON Web Token (JWT) is a JSON-base of operations access token that provides one or more than claims on a service. For case, a server could generate a token that has the merits "logged in as admin" and provide that to a client. The customer could then apply that token to prove that it is logged in as an admin.
The Consumer SDK uses the JSON Web Token provided by the awarding to communicate with the Fleet Engine. See Fleet Engine Authentication and Authorisation for more information.
The authorization token provides access to the following Fleet Engine services:
-
TripService- Gives the Consumer SDK admission to trip details, including vehicle position, route, and ETA. Authorization tokens for the trip service must include atripid:TRIP_IDmerits in the token'sauthorizationheader, whereTRIP_IDis the trip ID. -
VehicleService- Gives the Consumer SDK information about the fuzzed vehicle location for displaying the vehicle density layer and estimating pickup point ETAs. Considering the Consumer SDK uses only fuzzed locations, authorization tokens for the vehicle service practice not require avehicleidclaim.
JSON Web Token callbacks
The Consumer SDK registers an authorization token callback with the awarding during initialization. The SDK calls the awarding to get a token for all network requests that crave potency.
We strongly recommend that your callback implementation should cache authorization tokens and refresh them merely when the death time has expired. Tokens should be minted with a one-hour expiration.
The authority token callback specifies which service token is needed for the TripService service. It also provides the required tripId for the context.
The following code example demonstrates how to implement an authorization token callback.
grade JsonAuthTokenFactory implements AuthTokenFactory { individual static last String TOKEN_URL = "https://yourauthserver.example/token"; individual static class CachedToken { String tokenValue; long expiryTimeMs; String tripId; } private CachedToken token; /* * This method is called on a background thread. Blocking is OK, but simply * know that no data can exist obtained from FleetEngine until this method * returns. * * Return an empty string or throw an exception for unsupported service types. */ @Override public String getToken(AuthTokenContext context) { // If in that location is no existing token or token has expired, go get a new one. String tripId = context.getTripId(); if (tripId == null) { throw new RuntimeException("Trip ID is missing from AuthTokenContext"); } if (token == null || System.currentTimeMillis() > token.expiryTimeMs || !tripId.equals(token.tripId)) { token = fetchNewToken(tripId); } return token.tokenValue; } private static CachedToken fetchNewToken(String tripId) { String url = TOKEN_URL + "/" + tripId; CachedToken token = new CachedToken(); endeavor (Reader r = new InputStreamReader(new URL(url).openStream())) { com.google.gson.JsonObject obj = com.google.gson.JsonParser.parseReader(r).getAsJsonObject(); token.tokenValue = obj.become("ServiceToken").getAsString(); token.expiryTimeMs = obj.get("TokenExpiryMs").getAsLong(); /* * The expiry time could be an hour from at present, but just to try and avoid * passing expired tokens, nosotros decrease 5 minutes from that time. */ token.expiryTimeMs -= 5 * 60 * 1000; } take hold of (IOException e) { /* * It'due south OK to throw exceptions here, the ErrorListeners for each service * will receive the error thrown here. */ throw new RuntimeException("Could non get auth token", due east); } token.tripId = tripId; return token; } } Initialize the API
Before following these procedures, it is causeless that you have enabled the advisable services and the Consumer SDK.
Get the ConsumerApi case
To use the Consumer SDK, your app needs to initialize ConsumerApi asynchronously. The API is a singleton. The initialization method takes an AuthTokenFactory. The factory generates new JWT tokens for the user when necessary.
The providerId is the Project ID of your Google Cloud Project. Run into the Fleet Engine User Guide for more information on creating the projection.
Your app should implement the AuthTokenFactory as described in Consumer SDK Hallmark.
Task<ConsumerApi> consumerApiTask = ConsumerApi.initialize( this, "myProviderId", authTokenFactory); consumerApiTask.addOnCompleteListener(new OnCompleteListener<ConsumerApi>() { @Override public void onComplete(Task<ConsumerApi> task) { if (task.isSuccessful()) { ConsumerApi consumerApi = task.getResult(); } } }); Create the User Interface
You can use either ConsumerMapFragment or ConsumerMapView to create the user interface for your application. ConsumerMapFragment allows y'all to define your map using a Fragment while ConsumerMapView allows you to apply a View. Ride sharing functionality is the same in both ConsumerMapView and ConsumerMapFragment, and then you can choose one based on whether View or Fragment is better for your application.
Add support for API 19 (KitKat) and Vector drawables
If your app design requires back up for API 19 (KitKat) devices and vector drawables, add the post-obit code to your Action. This codes extends AppCompatActivity to utilize the Vector drawables in the Consumer SDK.
// ... import android.support.v7.app.AppCompatActivity; // ... public class ConsumerTestActivity extends AppCompatActivity { // ... } Add the map fragment or view
You create the map for displaying journey sharing in either an Android fragment or a view, which you ascertain in your application layout XML file (located in /res/layout). The fragment (or view) then provides access to the journey sharing map, which your app can access and modify. The map also provides a handle to the ConsumerController, which allows your app to control and customize the journeying sharing feel.
Journey sharing map and controller
You ascertain the journey sharing map as either a fragment (using ConsumerMapFragment), or as a view (using ConsumerMapView), as shown in the following code example. Your onCreate() method should then call getConsumerGoogleMapAsync(callback), which returns the ConsumerGoogleMap asynchronously in the callback. You then use the ConsumerGoogleMap to brandish journeying sharing, and it tin can be updated as needed by your app.
ConsumerMapFragment
Y'all define the fragment in your application layout XML file, as demonstrated in the following code instance.
<fragment xmlns:android="http://schemas.android.com/apk/res/android" android:name="com.google.android.libraries.mapsplatform.transportation.consumer.view.ConsumerMapFragment" android:id="@+id/consumer_map_fragment" android:layout_width="match_parent" android:layout_height="match_parent" /> The call to getConsumerGoogleMapAsync() should come from the onCreate() method.
public course SampleAppActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { // Notice the ConsumerMapFragment. ConsumerMapFragment consumerMapFragment = (ConsumerMapFragment) fragmentManager.findFragmentById(R.id.consumer_map_fragment); // Initiate the callback that returns the map. if (consumerMapFragment != null) { consumerMapFragment.getConsumerGoogleMapAsync( new ConsumerMapReadyCallback() { // The map returned in the callback is used to admission the ConsumerController. @Override public void onConsumerMapReady(@NonNull ConsumerGoogleMap consumerGoogleMap) { ConsumerController consumerController = consumerGoogleMap.getConsumerController(); } }); } } } ConsumerMapView
The view can be used either in a fragment or in an activity, as divers in your XML file.
<com.google.android.libraries.mapsplatform.transportation.consumer.view.ConsumerMapView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/consumer_map_view" android:layout_width="match_parent" android:layout_height="match_parent" /> The phone call to getConsumerGoogleMapAsync() should be from onCreate(). In addition to the callback parameter, it requires the containing activity or fragment, and GoogleMapOptions (which can be null), containing configuration attributes for the MapView. The activity or fragment base course must be either a FragmentActivity or a support Fragment (respectively), since they provide access to its lifecycle.
public form SampleAppActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { ConsumerMapView mapView = findViewById(R.id.consumer_map_view); if (mapView != aught) { mapView.getConsumerGoogleMapAsync( new ConsumerMapReadyCallback() { // The map returned in the callback is used to access the ConsumerController. @Override public void onConsumerMapReady(@NonNull ConsumerGoogleMap consumerGoogleMap) { ConsumerController consumerController = consumerGoogleMap.getConsumerController(); } }, this, goose egg); } } } A MapView in a fragment is the same as for the case higher up for MapView in an activeness, except that the fragment inflates the layout that includes the MapView in the fragment onCreateView() method.
public grade MapViewInFragment extends Fragment { @Override public View onCreateView( @NonNull LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Package packet) { render layoutInflater.inflate(R.layout.consumer_map_view, viewGroup, false); } } Adjusting the camera zoom to focus on a journey
The default My Location button congenital in to the Maps SDK centers the camera on the user location.
If in that location is an active Journey Sharing session, you may want to center the camera to focus on the journey instead of the user location.
Consumer SDK for Android built-in solution: AutoCamera
To permit you lot focus on the journey instead of the user location, the Consumer SDK provides an AutoCamera characteristic that is enabled by default. The camera zooms to focus on the journey sharing route and the next trip waypoint.
Customizing camera behavior
If yous crave more command of the photographic camera behavior, yous can disable or enable autocamera using ConsumerController.setAutoCameraEnabled().
ConsumerController.getCameraUpdate() returns the recommended camera bounds at that moment. You can then provide this CameraUpdate as an argument to GoogleMap.moveCamera() or GoogleMap.animateCamera().
Admission ridesharing and maps
To support ridesharing and map interaction in your application, yous need access to ConsumerGoogleMap and ConsumerController. ConsumerMapFragment and ConsumerMapView both asynchronously return ConsumerGoogleMap in ConsumerMapReadyCallback. ConsumerGoogleMap returns ConsumerController from getConsumerController(). You can access ConsumerGoogleMap and ConsumerController as follows.
private ConsumerGoogleMap consumerGoogleMap; individual ConsumerController consumerController; individual ConsumerMapView consumerMapView; consumerMapView.getConsumerGoogleMapAsync( new ConsumerMapReadyCallback() { @Override public void onConsumerMapReady(@NonNull ConsumerGoogleMap consumerMap) { consumerGoogleMap = consumerMap; consumerController = consumerMap.getConsumerController(); } }, this, zilch); ConsumerGoogleMap
ConsumerGoogleMap is a wrapper class for the GoogleMap class. It provides your app with the power to collaborate with the map using an API that is equivalent to GoogleMap. Using the consumer map allows your app and ride sharing to interact seamlessly with the same underlying GoogleMap. For example, GoogleMap merely allows a unmarried callback registration, but ConsumerGoogleMap supports dual registered callbacks. These callbacks allow your app and ride sharing to register callbacks which are called sequentially.
ConsumerController
ConsumerController provides access to ride sharing functionality such every bit monitoring trips, controlling trip status, and setting locations.
Ready journey sharing
Later the backend has matched a consumer with a vehicle, use JourneySharingSession to start the journeying sharing user interface. Journeying sharing shows the matched vehicle location and route. After implementing the SDK in your app, you lot can add the functionality for monitoring trips, listening for updates, and handling errors. The following procedures presume the backend services are in place and that your services for matching consumers with vehicles is operational.
-
Register a listener on a
TripModelobject to get details about the trip such as the ETA (Estimated Time of Inflow) and the altitude that the vehicle needs to travel earlier arrival.// Create a TripModel instance for listening to updates to the trip specified by this trip proper noun. String tripName = ...; TripModelManager tripModelManager = consumerApi.getTripModelManager(); TripModel tripModel = tripModelManager.getTripModel(tripName); // Create a JourneySharingSession example based on the TripModel. JourneySharingSession session = JourneySharingSession.createInstance(tripModel); // Add together the JourneySharingSession instance on the map for updating the UI. consumerController.showSession(session); // Register for trip update events. tripModel.registerTripCallback(new TripModelCallback() { @Override public void onTripETAToNextWaypointUpdated( TripInfo tripInfo, @Nullable Long timestampMillis) { // ... } @Override public void onTripActiveRouteRemainingDistanceUpdated( TripInfo tripInfo, @Nullable Integer distanceMeters) { // ... } // ... }); -
Configure your trip using
TripModelOptions.// Set refresh interval to ii seconds. TripModelOptions tripOptions = TripModelOptions.builder().setRefreshIntervalMillis(2000).build(); tripModel.setTripModelOptions(tripOptions);
Handle trip errors
The onTripRefreshError method surfaces errors that occur during trip monitoring. The mapping for Consumer SDK errors follow the same HTTP/RPC guidelines established for Google Cloud Platform. Common errors surfaced during trip monitoring include following:
| HTTP | RPC | Description |
|---|---|---|
| 400 | INVALID_ARGUMENT | Client specified an invalid trip name. The trip proper noun must follow the format providers/{provider_id}/trips/{trip_id}. The provider_id must be the ID of the Cloud Project endemic by the service provider. |
| 401 | UNAUTHENTICATED | Request non authenticated due to an invalid JWT token. This error will occur if the JWT token is signed without a trip id or the JWT token has expired. |
| 403 | PERMISSION_DENIED | Client does not have sufficient permission. This error occurs if the JWT token is invalid, the customer does non have permission, or the API is not enabled for the client project. The JWT token might be missing or the token is signed with a trip id that does not match requested trip id. |
| 429 | RESOURCE_EXHAUSTED | The resources quota is at zero or the rate of traffic exceeds the limit. |
| 503 | UNAVAILABLE | Service unavailable. Typically the server is down. |
| 504 | DEADLINE_EXCEEDED | Asking deadline exceeded. This will happen just if the caller sets a deadline that is shorter than the method's default deadline (i.eastward. requested deadline is not enough for the server to process the request) and the request did not cease inside the deadline. |
For more than information, see Consumer SDK Error Handling.
How To Delete Ride Sharing Services On Maps App,
Source: https://developers.google.com/maps/documentation/transportation-logistics/on-demand-rides-deliveries-solution/trip-order-progress/consumer-sdk/consumer_sdk_quickstart_android
Posted by: conradforearephe.blogspot.com

0 Response to "How To Delete Ride Sharing Services On Maps App"
Post a Comment