برای جزئیات بیشتر در مورد هر مرحله، بخش های زیر را ببینید.
پروژه توسعه خود را تنظیم کنید
اگر پروژه توسعه کنسول Google Cloud و کلید API برای پروژه تحرک خود ندارید، باید یکی را تنظیم کنید. برای جزئیات، به ایجاد پروژه خود در راهنمای Fleet Engine مراجعه کنید.
وقتی پروژه توسعه خود را برای Consumer SDK انتخاب میکنید، همان پروژه کنسول Google Cloud و کلید API را انتخاب کنید که برای Fleet Engine استفاده میکنید.
Consumer SDK را به برنامه خود اضافه کنید
Consumer SDK از مخزن Google Maven در دسترس است. این مخزن شامل فایلهای Project Object Model (.pom) SDK و Javadocs است. برای افزودن Consumer SDK به برنامه خود، وابستگی های Consumer SDK و Maps SDK را به پیکربندی Gradle یا Maven خود اضافه کنید.
در مثالهای زیر، VERSION_NUMBER با نسخه مورد نیاز Consumer SDK جایگزین کنید:
هنگامی که Consumer SDK را به برنامه خود اضافه کردید، کلید API را اضافه کنید. شما باید از کلید API پروژه ای که هنگام راه اندازی پروژه توسعه خود به دست آورده اید استفاده کنید. برای جزئیات بیشتر، به تنظیم پروژه توسعه خود در مرحله 3 این راهنما مراجعه کنید.
این بخش نحوه ذخیره کلید API خود را توضیح می دهد تا بتواند با امنیت بیشتری توسط برنامه شما ارجاع دهد. برای اطلاعات بیشتر در مورد بهترین شیوه های امنیتی کلید API، مقاله پلتفرم نقشه های Google را در مورد بهترین شیوه های امنیتی API ببینید.
اگر از Consumer SDK در برنامه خود استفاده می کنید، باید متن منبع و مجوزهای منبع باز را به عنوان بخشی از بخش اعلامیه های قانونی برنامه خود قرار دهید. بهتر است انتسابها را بهعنوان یک آیتم منوی مستقل یا بهعنوان بخشی از یک آیتم درباره منو درج کنید.
می توانید اطلاعات مجوز را در فایل "third_party_licenses.txt" در فایل AAR بایگانی نشده بیابید.
تاریخ آخرین بهروزرسانی 2025-09-04 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2025-09-04 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eThis guide outlines the setup and configuration process for using the Consumer SDK for Android with Google Cloud Console.\u003c/p\u003e\n"],["\u003cp\u003eSteps include setting up a development project and API key, adding the Consumer SDK and Maps SDK dependencies to your app (explicitly defining the Maps SDK version), and securely adding your API key to your app.\u003c/p\u003e\n"],["\u003cp\u003eFor security, store the API key in the \u003ccode\u003elocal.properties\u003c/code\u003e file instead of the version control system, and reference it within your \u003ccode\u003eAndroidManifest.xml\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eEnsure your app includes required attribution text and open source licenses, typically placed in a legal notices or "About" section, with details found within the "third_party_licenses.txt" file.\u003c/p\u003e\n"],["\u003cp\u003eYour Android app must target a minimum SDK version of 23 or higher to utilize the Consumer SDK.\u003c/p\u003e\n"]]],[],null,["To set up and configure a Google Cloud console to use the Consumer SDK for\nAndroid, follow these steps.\n\n1. [Set up your development project](#auth-project).\n2. [Add the Consumer SDK to your app](#add-sdk).\n3. [Add the API key to your app](#add-key).\n4. [Include the required attributions in your app](#attrib).\n\nFor more details on each step, see the following sections.\n| **Note:** Your app must target `minSdkVersion` 23 or higher.\n\nSet up your development project\n\nIf you don't have a Google Cloud console development project and an API key for\nyour mobility project, you need to set one up. For details, see\n[Create your project](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/create-project) in the Fleet Engine guide.\n\nWhen you're selecting your development project for the Consumer SDK, select the\nsame Google Cloud console project and API key that you are using for Fleet Engine.\n\nAdd the Consumer SDK to your app\n\nThe Consumer SDK is available from the Google Maven repository. The repository\nincludes the SDK's Project Object Model (.pom) files and Javadocs. To add the\nConsumer SDK to your app, add the Consumer SDK and Maps SDK dependencies to your\nGradle or Maven configuration.\n| **Note:** The Consumer SDK depends on the Maps SDK. Set your dependency to an **explicitly defined** version of Maps SDK, as shown in this example. Otherwise, the Consumer SDK uses the minimum-required version of the Maps SDK, which might cause issues if your app relies on features available in later Maps SDK versions.\n\nIn the following examples, substitute `VERSION_NUMBER` with the required\nversion of the Consumer SDK: \n\nGradle\n\nAdd the following to your `build.gradle`: \n\n dependencies {\n ...\n implementation 'com.google.android.libraries.mapsplatform.transportation:transportation-consumer:\u003cvar translate=\"no\"\u003eVERSION_NUMBER\u003c/var\u003e'\n implementation \"com.google.android.gms:play-services-maps:18.1.0\"\n }\n\nMaven\n\nAdd the following to your `pom.xml`: \n\n \u003cdependencies\u003e\n ...\n \u003cdependency\u003e\n \u003cgroupId\u003ecom.google.android.libraries.mapsplatform.transportation\u003c/groupId\u003e\n \u003cartifactId\u003etransportation-consumer\u003c/artifactId\u003e\n \u003cversion\u003e\u003cvar translate=\"no\"\u003eVERSION_NUMBER\u003c/var\u003e\u003c/version\u003e\n \u003c/dependency\u003e\n \u003cdependency\u003e\n \u003cgroupId\u003ecom.google.android.gms\u003c/groupId\u003e\n \u003cartifactId\u003eplay-services-maps\u003c/artifactId\u003e\n \u003cversion\u003e18.1.0\u003c/version\u003e\n \u003c/dependency\u003e\n \u003c/dependencies\u003e\n\nAdd the API key to your app\n\nOnce you have added the Consumer SDK to your app, add the API key. You must use\nthe project API key you obtained when you set up your development project. For\nmore details, see [Set up your development project](#auth-project) in Step 3 of this guide.\n\nThis section describes how to store your API key so that it can be more securely\nreferenced by your app. For more information on API key security best practices,\nsee the Google Maps Platform article on [API security best practices](/maps/api-security-best-practices#restrict_apikey).\n| **Important:** Don't check your API key into your version control system. Instead, store it in the `local.properties` file, which is located in the root directory of your project. For more information about the `local.properties` file, see [Gradle properties files](https://developer.android.com/studio/build#properties-files).\n\nTo streamline this task, you can use the GitHub documentation [Secrets Gradle\nPlugin for Android](https://github.com/google/secrets-gradle-plugin).\n\nTo install the plugin and store your API key:\n\n1. Open your root-level `build.gradle` file and add the following code to the\n `dependencies` element under `buildscript`.\n\n Groovy \n\n buildscript {\n dependencies {\n // ...\n classpath \"com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.0\"\n }\n }\n\n Kotlin \n\n buildscript {\n dependencies {\n // ...\n classpath(\"com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.0\")\n }\n }\n\n2. Open your app-level `build.gradle` file and add the following code to the\n `plugins` element.\n\n Groovy \n\n id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'\n\n Kotlin \n\n id(\"com.google.android.libraries.mapsplatform.secrets-gradle-plugin\")\n\n3. If you use Android Studio, sync your project with Gradle. For details, see\n [Sync your project with Gradle](https://developer.android.com/studio/build#sync-files) in the Android documentation.\n\n4. Open the `local.properties` in your project level directory, and then add\n the following code. Replace `YOUR_API_KEY` with your API key.\n\n MAPS_API_KEY=\u003cvar translate=\"no\"\u003eYOUR_API_KEY\u003c/var\u003e\n5. In your `AndroidManifest.xml` file, go to `com.google.android.geo.API_KEY`\n and update the `android:value` attribute as follows:\n\n \u003cmeta-data\n android:name=\"com.google.android.geo.API_KEY\"\n android:value=\"${MAPS_API_KEY}\" /\u003e\n\nThe following example shows a complete manifest for a sample app: \n\n \u003cmanifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n package=\"com.example.consumerapidemo\"\u003e\n \u003cuses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\" /\u003e\n \u003capplication\n android:allowBackup=\"true\"\n android:icon=\"@mipmap/ic_launcher\"\n android:label=\"@string/app_name\"\n android:supportsRtl=\"true\"\n android:theme=\"@style/_AppTheme\"\u003e\n\n \u003cmeta-data\n android:name=\"com.google.android.geo.API_KEY\"\n android:value=\"${MAPS_API_KEY}\" /\u003e\n\n \u003cactivity android:name=\".MainActivity\"\u003e\n \u003cintent-filter\u003e\n \u003caction android:name=\"android.intent.action.MAIN\" /\u003e\n \u003ccategory android:name=\"android.intent.category.LAUNCHER\" /\u003e\n \u003c/intent-filter\u003e\n \u003c/activity\u003e\n \u003c/application\u003e\n \u003c/manifest\u003e\n\nInclude the required attributions in your app\n\nIf you use the Consumer SDK in your app, you must include attribution text and\nopen source licenses as part of your app's legal notices section. It's best to\ninclude the attributions as an independent menu item or as part of an **About**\nmenu item.\n\nYou can find the license information in the \"third_party_licenses.txt\" file in\nthe unarchived AAR file.\n\nRefer to \u003chttps://developers.google.com/android/guides/opensource\u003e on how to\ninclude open source notices.\n\nWhat's next\n\n[Get authentication tokens](/maps/documentation/mobility/journey-sharing/on-demand/android/auth-sdk)"]]