نموذج رمز برمجي لحزمة تطوير البرامج بالاستناد إلى بيانات "خرائط Google" لتطبيقات Android
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
اختيار النظام الأساسي:
Android
iOS
JavaScript
يتضمّن مستودع حزمة تطوير البرامج بالاستناد إلى بيانات "خرائط Google" لتطبيقات Android على GitHub
عيّنات توضّح كيفية استخدام حزمة تطوير البرامج بالاستناد إلى بيانات "خرائط Google" لتطبيقات Android
في تطبيق Android.
يحتوي المستودع على تطبيق ApiDemos، وهو تطبيق نموذجي يتيح لك إنشاء النماذج وتشغيلها من تطبيق Android واحد. استورِد التطبيق وأنشئه، وأضِف مفتاح واجهة برمجة التطبيقات، واطّلِع على العرض التوضيحي، واستخدِم نموذج الرمز البرمجي المقدَّم كنقطة بداية لتطبيقك.
عند تشغيل تطبيق العيّنات، ستظهر قائمة بالعيّنات المتاحة التي يمكنك تشغيلها على جهازك. حدِّد أحد الخيارات. على سبيل المثال، انقر على الخريطة الأساسية.
تحديد المشاكل وحلّها: إذا تم تشغيل التطبيق النموذجي بنجاح ولكن لم تظهر خريطة، تأكَّد من أنّك أضفت مفتاح واجهة برمجة التطبيقات إلى ملف البيان الخاص بالتطبيق، كما هو موضّح في استخدام مفاتيح واجهة برمجة التطبيقات.
قائمة التطبيقات النموذجية لحزمة تطوير البرامج بالاستناد إلى بيانات "خرائط Google" لتطبيقات Android
في ما يلي قائمة بالأنشطة الرئيسية النموذجية الواردة في تطبيق ApiDemos الخاص بحزمة تطوير البرامج بالاستناد إلى بيانات "خرائط Google" لنظام التشغيل Android، وقد تم إعادة إنتاجها في الصفحات المرتبطة لتسهيل الرجوع إليها. اطّلِع على مجلد Kotlin أو Java
للحصول على القائمة الكاملة للعينات المتاحة.
استنساخ العيّنات وتشغيلها
يجب تثبيت Git لتشغيل هذا النموذج محليًا. ينسخ الأمر التالي مستودع التطبيق النموذجي.
git clone git@github.com:googlemaps-samples/android-samples.git
استورِد نموذج المشروع إلى "استوديو Android" باتّباع الخطوات التالية:
- في "استوديو Android"، انقر على ملف (File) > جديد (New) > استيراد مشروع (Import Project).
انتقِل إلى الموقع الجغرافي الذي حفظت فيه المستودع واختَر دليل المشروع الخاص بلغة Kotlin أو Java:
- Kotlin:
PATH-REPO/android-samples/ApiDemos/kotlin
- Java:
PATH-REPO/android-samples/ApiDemos/java
- انقر على فتح. ينشئ "استوديو Android" مشروعك باستخدام أداة الإصدار Gradle.
- أنشِئ ملف
secrets.properties
فارغًا في الدليل نفسه الذي يحتوي على ملف local.properties
الخاص بمشروعك. لمزيد من المعلومات حول هذا الملف، يُرجى الاطّلاع على إضافة مفتاح واجهة برمجة التطبيقات إلى المشروع.
- احصل على مفتاح واجهة برمجة تطبيقات من مشروعك الذي تم تفعيل حزمة تطوير البرامج بالاستناد إلى بيانات "خرائط Google" لنظام التشغيل Android فيه.
أضِف السلسلة التالية إلى secrets.properties
، مع استبدال YOUR_API_KEY بقيمة مفتاح واجهة برمجة التطبيقات:
MAPS_API_KEY=YOUR_API_KEY
- شغِّل التطبيق.
تطبيق نموذجي للخرائط على Wear OS
يتوفّر نموذج تطبيق لحزمة تطوير البرامج "خرائط Google" لنظام التشغيل Android على Wear OS على GitHub، ويمكنك استخدامه كنقطة بداية عند إنشاء تطبيق متوافق مع الأجهزة القابلة للارتداء. يوضّح لك النموذج كيفية إعداد خريطة Google أساسية على Wear OS.
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eThis page provides access to the Maps SDK for Android sample code and apps, including a comprehensive ApiDemos app containing various map feature examples.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can clone the sample repository from GitHub, import it into Android Studio, add their API key, and run the app to explore different map functionalities.\u003c/p\u003e\n"],["\u003cp\u003eThe ApiDemos app showcases key features such as basic maps, markers, events, polylines, polygons, and My Location, with code samples readily available for use.\u003c/p\u003e\n"],["\u003cp\u003eTroubleshooting guidance is provided if the map doesn't display, directing users to verify their API key configuration.\u003c/p\u003e\n"],["\u003cp\u003eA separate sample app specifically for Wear OS is available on GitHub, demonstrating how to integrate Google Maps into wearable applications.\u003c/p\u003e\n"]]],["The Maps SDK for Android samples are available on GitHub. To use them, clone the repository, import the ApiDemos project into Android Studio (either Kotlin or Java), and add your API key to the `secrets.properties` file. Run the app to view a list of samples like Basic Map, Markers, and Polylines. A separate Wear OS sample is also available on GitHub, showing basic map setup for wearable apps. Ensure your API key is correctly added to the app manifest if you encounter map display issues.\n"],null,["Select platform: [Android](/maps/documentation/android-sdk/examples \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/examples \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/examples \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\nThe Maps SDK for Android repository on [GitHub](https://github.com/googlemaps-samples/android-samples)\nincludes samples illustrating the use of the Maps SDK for Android in\nyour Android app.\n\nThe repository contains the [ApiDemos](https://github.com/googlemaps-samples/android-samples/tree/main/ApiDemos) app, a sample app that lets\nyou build and run the samples from a single Android app. Import and build the\napp, add your API key, view the demo, and use the sample code supplied as a\nstarting point for your app.\n\nWhen you run the sample app, it displays a list of available samples that you\ncan run on your own device. Select one of the options. For example, click\n**Basic Map**.\n\n**Troubleshooting:** If the sample app runs successfully but you don't see a\nmap, check that you've added your API key to the app's manifest file, as\ndescribed in [Using API Keys](/maps/documentation/android-sdk/get-api-key).\n\nMaps SDK for Android sample app list\n\nKey sample activities contained in the Maps SDK for Android\n[ApiDemos](https://github.com/googlemaps-samples/android-samples/tree/main/ApiDemos) app are listed below and reproduced at the linked pages\nfor quick reference. See the [Kotlin](https://github.com/googlemaps-samples/android-samples/tree/main/ApiDemos/kotlin/app/src/main/java/com/example/kotlindemos) or [Java](https://github.com/googlemaps-samples/android-samples/tree/main/ApiDemos/java/app/src/main/java/com/example/mapdemo)\nfolder for the full list of available samples.\n\n- [Basic map](/maps/documentation/android-sdk/examples/basic-map)\n- [Markers](/maps/documentation/android-sdk/examples/marker)\n- [Advanced markers](/maps/documentation/android-sdk/examples/advanced-marker)\n- [My Location](/maps/documentation/android-sdk/examples/my-location)\n- [Events](/maps/documentation/android-sdk/examples/events)\n- [Polylines](/maps/documentation/android-sdk/examples/polyline)\n- [Polygons](/maps/documentation/android-sdk/examples/polygon)\n\nClone and run the samples\n\nGit is required to run this sample locally. The following command clones the sample\napplication repository. \n\n```\ngit clone git@github.com:googlemaps-samples/android-samples.git\n```\n\nImport the sample project into Android Studio:\n\n1. In Android Studio, select **File \\\u003e New \\\u003e Import Project**.\n2. Go to the location where you saved the repository and select the project directory for\n Kotlin or Java:\n\n - **Kotlin** : \u003cvar translate=\"no\"\u003ePATH-REPO\u003c/var\u003e`/android-samples/ApiDemos/kotlin`\n - **Java** : \u003cvar translate=\"no\"\u003ePATH-REPO\u003c/var\u003e`/android-samples/ApiDemos/java`\n3. Select **Open**. Android Studio builds your project, using the Gradle build tool.\n4. Create a blank `secrets.properties` file in the same directory as your project's `local.properties` file. For more information about this file, see [Add your API key to the project](/maps/documentation/android-sdk/config#step_3_add_your_api_key_to_the_project).\n5. [Get an API key](/maps/documentation/android-sdk/get-api-key) from your project with the [Maps SDK for Android enabled](/maps/documentation/android-sdk/cloud-setup#enabling-apis).\n6. Add the following string to `secrets.properties`, replacing **YOUR_API_KEY** with the value of\n your API key:\n\n ```scdoc\n MAPS_API_KEY=YOUR_API_KEY\n ```\n7. Run the app.\n\nSample app for maps on Wear OS\n\nA sample app for Maps SDK for Android on Wear OS is\navailable on [GitHub](https://github.com/googlemaps-samples/android-samples/tree/main/WearOS), which you can use as a starting point when\nbuilding a wearable app. The sample shows you how to set up a basic Google Map\non Wear OS."]]