Maps SDK สำหรับการตั้งค่ายูทิลิตีของ Android
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เลือกแพลตฟอร์ม
แอนดรอยด์
iOS
หน้านี้จะอธิบายวิธีตั้งค่า
Maps SDK สำหรับ Android
ไลบรารียูทิลิตี และเรียกใช้แอปเดโมที่รวมอยู่ในไลบรารี
สิ่งที่ต้องมีก่อนและหมายเหตุ
ไลบรารียูทิลิตีของ Maps SDK สำหรับ Android สนับสนุน Android
API
ระดับ 15 ขึ้นไป เมื่อตั้งค่าเป้าหมายบิลด์ของโปรเจ็กต์ ให้ตรวจสอบว่าคุณใช้เวอร์ชันล่าสุด
ระดับ API ของ Android
แหล่งอ้างอิง
เอกสาร มีอยู่ใน GitHub
ขั้นตอนที่ 1 ติดตั้งไลบรารียูทิลิตี Maps SDK สำหรับ Android
เพิ่มทรัพยากร Dependency ต่อไปนี้ลงในไฟล์ build.gradle.kts
ของแอป
dependencies {
// Utility Library for Maps SDK for Android
// You do not need to add a separate dependency for the Maps SDK for Android
// since this library builds in the compatible version of the Maps SDK.
implementation("com.google.maps.android:android-maps-utils:3.14.0")
}
ใช้ยูทิลิตีจากไลบรารีรายการใดรายการหนึ่ง เช่น
เครื่องหมาย
การจัดกลุ่ม
แผนที่ความหนาแน่น หรือ
อื่นๆ
ยูทิลิตี
ขั้นตอนที่ 2 (ไม่บังคับ) ติดตั้ง Maps SDK สำหรับไลบรารี KTX ยูทิลิตีของ Android
ไลบรารียูทิลิตีของ Maps SDK สำหรับ Android มาพร้อมกับส่วนขยาย Kotlin ที่สอดคล้องกัน
(KTX) ไลบรารีนี้มีฟีเจอร์ภาษา Kotlin เช่น ฟังก์ชันส่วนขยายที่ชื่อ
และอาร์กิวเมนต์เริ่มต้นเพื่อให้คุณเขียน Kotlin ได้กระชับและมีเอกลักษณ์ หากคุณไม่ใช่
คุณข้ามขั้นตอนนี้ได้
หากต้องการใช้ไลบรารีนี้ ให้เพิ่มทรัพยากร Dependency ต่อไปนี้นอกเหนือจากพารามิเตอร์
ทรัพยากร Dependency android-maps-utils
ไปยังไฟล์ build.gradle.kts
ของแอป:
dependencies {
// KTX for the Maps SDK for Android Utility Library
implementation("com.google.maps.android:maps-utils-ktx:5.2.0")
}
ดูหน้า Maps KTX GitHub
เพื่อดูข้อมูลเพิ่มเติมเกี่ยวกับไลบรารีนี้
ขั้นตอนที่ 3 ดูซอร์สโค้ดของไลบรารียูทิลิตีของ Maps SDK สำหรับ Android
เนื่องจากไลบรารียูทิลิตีเป็นโอเพนซอร์ส คุณสามารถดาวน์โหลด
android-maps-utils
ไลบรารีไปยังเครื่องของคุณเพื่อปรับแต่ง ดูแอปเดโม หรือหากคุณต้องการเพียงแค่ทำความเข้าใจวิธี
ที่ไลบรารีใช้งานได้ คุณสามารถทำได้โดย
การโคลนที่เก็บ (แนะนำ
เพื่อรับการอัปเดตอัตโนมัติ) หรือ
กำลังดาวน์โหลด
ไฟล์ ZIP หากคุณต้องการปรับแต่งไลบรารี คุณควร
แยกที่เก็บ
ที่เก็บประกอบด้วยรายการต่อไปนี้
- แอปพลิเคชันเดโมในไดเรกทอรี
demo
- ไลบรารีของยูทิลิตีในไดเรกทอรี
library
- ไฟล์ต่างๆ ที่มีใบอนุญาต ผู้ร่วมให้ข้อมูล และข้อมูล Readme
- การกำหนดค่าบิลด์ Gradle สำหรับใช้กับ Android Studio
เรียกใช้แอปการสาธิตยูทิลิตี
ที่เก็บ GitHub สำหรับไลบรารียูทิลิตีจะจัดส่งพร้อมกับแอปเดโมที่มีตัวอย่าง
ของยูทิลิตีแต่ละแบบ ทำตามขั้นตอนต่อไปนี้เพื่อเรียกใช้แอปเดโม
อุปกรณ์ Android ของคุณ
- ดาวน์โหลดที่เก็บโดยใช้ตัวเลือกใดตัวเลือกหนึ่งที่กล่าวถึงข้างต้น
- ใน Android Studio ให้เลือกไฟล์ -> ใหม่ -> นำเข้าโปรเจ็กต์
- เรียกดูและเลือก (ดับเบิลคลิก)
ไดเรกทอรี android-maps-utils ที่สร้างขึ้นเมื่อคุณ
โคลนไลบรารียูทิลิตีแล้ว ตอนนี้ Android Studio จะสร้างโปรเจ็กต์แล้ว
- หากคุณใช้อุปกรณ์ Android แทนโปรแกรมจำลอง ให้ทำดังนี้
เปิดใช้โหมดนักพัฒนาซอฟต์แวร์
จากนั้นแนบอุปกรณ์ Android เข้ากับคอมพิวเตอร์
เพิ่มบรรทัดเดียวลงใน local.properties
ซึ่งมีลักษณะดังนี้:
MAPS_API_KEY=YOUR_API_KEY
โดยที่ YOUR_API_KEY คือคีย์ API ที่คุณได้รับตามที่อธิบายไว้ใน
การใช้คีย์ API
- สร้างและเรียกใช้แอปสาธิต
แอปควรเปิดในอุปกรณ์ Android โดยแสดงรายการยูทิลิตี
ซึ่งรวมถึงการจัดกลุ่ม, poyutil, แผนที่ความหนาแน่น และอื่นๆ นอกจากนี้ คุณยังค้นหาแอปได้ใน
รายชื่อแอปภายใต้ชื่อ Maps Utils Demo
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-31 UTC
[null,null,["อัปเดตล่าสุด 2025-08-31 UTC"],[[["\u003cp\u003eThis page explains how to set up the Maps SDK for Android utility library and run its demo app, allowing you to utilize features like marker clustering and heatmaps.\u003c/p\u003e\n"],["\u003cp\u003eThe library supports Android API level 15 and above, requiring you to add a specific dependency to your app's \u003ccode\u003ebuild.gradle.kts\u003c/code\u003e file for implementation.\u003c/p\u003e\n"],["\u003cp\u003eAn optional Kotlin extensions (KTX) library provides Kotlin-specific features for more concise coding if you are developing in Kotlin.\u003c/p\u003e\n"],["\u003cp\u003eThe open-source nature of the library allows for customization by cloning or downloading the \u003ccode\u003eandroid-maps-utils\u003c/code\u003e repository from GitHub.\u003c/p\u003e\n"],["\u003cp\u003eYou can explore the functionalities of the library by running the demo app included in the repository, requiring steps like adding your API key and building the project in Android Studio.\u003c/p\u003e\n"]]],["To set up the Maps SDK for Android utility library, add the `android-maps-utils` dependency to your `build.gradle.kts` file. Optionally, include the `maps-utils-ktx` dependency for Kotlin features. The library, which supports Android API level 15 and above, is open-source and can be downloaded from GitHub. To run the included demo app, clone the repository, import the project into Android Studio, enable developer mode on your Android device, add your API key to `local.properties`, and then build and run the app.\n"],null,["Select platform: [Android](/maps/documentation/android-sdk/utility/setup \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/utility/setup \"View this page for the iOS platform docs.\")\n\nThis page describes how to set up the\n[Maps SDK for Android\nutility library](https://github.com/googlemaps/android-maps-utils), and to run the demo app included in the library.\n\nPrerequisites and notes\n\nThe Maps SDK for Android utility library supports Android\n[API\nlevel](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) 15 and above. When setting your project build target, make sure you use the latest\nAndroid API level.\n\nThe\n[reference\ndocumentation](http://googlemaps.github.io/android-maps-utils/javadoc/) is available on GitHub.\n\nStep 1. Install the Maps SDK for Android utility library\n\nAdd the following dependency to your app's `build.gradle.kts` file: \n\n```carbon\ndependencies {\n\n\n // Utility Library for Maps SDK for Android\n // You do not need to add a separate dependency for the Maps SDK for Android\n // since this library builds in the compatible version of the Maps SDK.\n implementation(\"com.google.maps.android:android-maps-utils:3.14.0\")\n}\n```\n\nUse one of the utilities from the library, such as\n[marker\nclustering](/maps/documentation/android-sdk/utility/marker-clustering),\n[heatmaps](/maps/documentation/android-sdk/utility/heatmap), or\nthe [other\nutilities](/maps/documentation/android-sdk/utility).\n\nStep 2. (Optional) Install the Maps SDK for Android utility KTX library\n\nThe Maps SDK for Android utility library comes with a corresponding Kotlin extensions\n(KTX) library. This library provides Kotlin language features---such as extension functions, named\nand default arguments---to enable you to write concise and idiomatic Kotlin. If you are not\ndeveloping in Kotlin, you can skip this step.\n\nTo use this library, add the following dependency, in addition to the\n`android-maps-utils` dependency, to your app's `build.gradle.kts` file: \n\n```carbon\ndependencies {\n\n // KTX for the Maps SDK for Android Utility Library\n implementation(\"com.google.maps.android:maps-utils-ktx:5.2.0\")\n}\n```\n\nCheck out the [Maps KTX GitHub](https://github.com/googlemaps/android-maps-ktx) page\nfor additional information about this library.\n\nStep 3. View the Maps SDK for Android utility library source code\n\nSince the utility library is open source, you can download the\n[android-maps-utils](https://github.com/googlemaps/android-maps-utils)\nlibrary to your machine to customize it, view the demo app, or if you just want to understand how\nthe library works. You can do so by\n[cloning](https://github.com/googlemaps/android-maps-utils.git) the repo (recommended,\nto receive automatic updates) or\n[downloading\na zip file](https://github.com/googlemaps/android-maps-utils/archive/master.zip). If you want to customize the library, you should\n[fork the repo](https://help.github.com/articles/fork-a-repo).\n\nThe repository includes:\n\n- A demo application, in the `demo` directory.\n- The library of utilities, in the `library` directory.\n- Various files containing license, contributors, and readme information.\n- Gradle build configuration, for use with Android Studio.\n\nRun the utility demo app\n\nThe GitHub repository for the utility library ships with a demo app that includes sample\nimplementations of each utility. Follow these steps to run the demo app on\nyour Android device.\n\n1. Download the repository using one of the options mentioned above.\n2. In Android Studio, choose **File -\\\u003e New -\\\u003e Import Project**.\n3. Browse to and select (double-click) the **android-maps-utils** directory that was created when you cloned the utility library. Android Studio now builds the project.\n4. If you are using an Android device instead of an emulator, make sure to [enable developer mode](https://developer.android.com/tools/device.html#setting-up). Then attach the Android device to your computer.\n5. Add a single line to `local.properties` that looks like this:\n\n ```scdoc\n MAPS_API_KEY=YOUR_API_KEY\n ```\n\n Where \u003cvar translate=\"no\"\u003eYOUR_API_KEY\u003c/var\u003e is the API key you obtained as described in\n [Using API Keys](/maps/documentation/android-sdk/get-api-key).\n6. Build and run the **demo** app.\n\nThe app should open on the Android device, displaying a list of utilities\nincluding clustering, poyutil, heatmap, and more. You can also find the app in\nyour app list, under the name **Maps Utils Demo**."]]