لمزيد من التفاصيل حول كل خطوة، يُرجى الاطّلاع على الأقسام التالية.
إعداد مشروع التطوير
إذا لم يكن لديك مشروع تطوير على Google Cloud Console ومفتاح API لمشروع التنقّل الخاص بك، عليك إعداد أحدهما. للاطّلاع على التفاصيل، راجِع مقالة إنشاء مشروعك في دليل Fleet Engine.
عند اختيار مشروع التطوير لحزمة Consumer SDK، اختَر مشروع Google Cloud Console نفسه ومفتاح واجهة برمجة التطبيقات الذي تستخدمه مع Fleet Engine.
إضافة حزمة Consumer SDK إلى تطبيقك
تتوفّر حزمة Consumer SDK من مستودع Google Maven. يتضمّن المستودع ملفات Project Object Model (.pom) وJavadocs الخاصة بحزمة SDK. لإضافة حزمة Consumer SDK إلى تطبيقك، أضِف تبعيات حزمة Consumer SDK وحزمة Maps SDK إلى إعدادات Gradle أو Maven.
في الأمثلة التالية، استبدِل VERSION_NUMBER بالإصدار المطلوب من حزمة Consumer SDK:
بعد إضافة حزمة Consumer SDK إلى تطبيقك، أضِف مفتاح واجهة برمجة التطبيقات. يجب استخدام مفتاح واجهة برمجة التطبيقات الخاص بالمشروع الذي حصلت عليه عند إعداد مشروع التطوير. لمزيد من التفاصيل، يُرجى الاطّلاع على إعداد مشروع التطوير في الخطوة 3 من هذا الدليل.
يوضّح هذا القسم كيفية تخزين مفتاح واجهة برمجة التطبيقات بطريقة تتيح لتطبيقك الرجوع إليه بشكل أكثر أمانًا. لمزيد من المعلومات حول أفضل الممارسات المتعلّقة بأمان مفتاح واجهة برمجة التطبيقات، يمكنك الاطّلاع على مقالة أفضل الممارسات المتعلّقة بأمان واجهة برمجة التطبيقات على "منصة خرائط Google".
إذا كنت تستخدم "استوديو Android"، عليك مزامنة مشروعك مع Gradle. لمزيد من التفاصيل، يُرجى الاطّلاع على مقالة مزامنة مشروعك مع Gradle في مستندات Android.
افتح ملف local.properties في دليل مستوى مشروعك، ثم أضِف الرمز التالي. استبدِل YOUR_API_KEY بمفتاح واجهة برمجة التطبيقات.
MAPS_API_KEY=YOUR_API_KEY
في ملف AndroidManifest.xml، انتقِل إلى com.google.android.geo.API_KEY وعدِّل السمة android:value على النحو التالي:
إذا كنت تستخدم حزمة 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)"]]