พบกับแผนที่แบบใหม่ใน Google Maps Platform เร็วๆ นี้ การอัปเดตการจัดรูปแบบแผนที่นี้มีชุดสีเริ่มต้นใหม่ รวมถึงการปรับปรุงประสบการณ์และความสามารถในการใช้งานแผนที่ ระบบจะอัปเดตรูปแบบแผนที่ทั้งหมดโดยอัตโนมัติในเดือนมีนาคม 2025 หากต้องการทราบข้อมูลเพิ่มเติมเกี่ยวกับความพร้อมให้บริการและวิธีเลือกใช้ก่อนหน้านี้ โปรดดู
รูปแบบแผนที่ใหม่สำหรับ Google Maps Platform
โค้ดตัวอย่างของ Maps SDK สำหรับ Android
ที่เก็บข้อมูล Maps SDK สำหรับ Android ใน GitHub มีตัวอย่างที่แสดงการใช้ Maps SDK สำหรับ Android ในแอป Android
ที่เก็บประกอบด้วยแอป ApiDemos ซึ่งเป็นแอปตัวอย่างที่ช่วยให้คุณสร้างและเรียกใช้ตัวอย่างจากแอป Android แอปเดียว นำเข้าและสร้างแอป เพิ่มคีย์ API ดูตัวอย่าง และใช้โค้ดตัวอย่างที่ให้มาเพื่อเป็นจุดเริ่มต้นสําหรับแอป
เมื่อคุณเรียกใช้แอปตัวอย่าง แอปจะแสดงรายการตัวอย่างที่ใช้ได้ซึ่งคุณเรียกใช้ได้ในอุปกรณ์ของคุณเอง เลือกตัวเลือกใดตัวเลือกหนึ่ง เช่น คลิกแผนที่พื้นฐาน
การแก้ปัญหา: หากแอปตัวอย่างทํางานสําเร็จแต่ไม่เห็นแผนที่ ให้ตรวจสอบว่าคุณได้เพิ่มคีย์ API ลงในไฟล์ Manifest ของแอปแล้ว ตามที่อธิบายไว้ในการใช้คีย์ API
รายการแอปตัวอย่างของ Maps SDK สำหรับ Android
ตัวอย่างกิจกรรมหลักที่อยู่ในแอป ApiDemos ของ Maps SDK สำหรับ Android มีอยู่ในรายการด้านล่างและสร้างขึ้นใหม่ในหน้าเว็บที่ลิงก์ไว้เพื่อใช้อ้างอิงอย่างรวดเร็ว ดูรายการตัวอย่างทั้งหมดที่ใช้ได้ได้ที่โฟลเดอร์ Kotlin หรือ Java
โคลนและเรียกใช้ตัวอย่าง
คุณต้องใช้ Git เพื่อเรียกใช้ตัวอย่างนี้ในเครื่อง คำสั่งต่อไปนี้จะโคลนที่เก็บแอปพลิเคชันตัวอย่าง
git clone git@github.com:googlemaps-samples/android-samples.git
นําเข้าโปรเจ็กต์ตัวอย่างไปยัง Android Studio โดยทำดังนี้
- ใน Android Studio ให้เลือกไฟล์ > ใหม่ > นำเข้าโปรเจ็กต์
ไปที่ตำแหน่งที่คุณบันทึกที่เก็บไว้ แล้วเลือกไดเรกทอรีโปรเจ็กต์สำหรับ Kotlin หรือ Java
- Kotlin:
PATH-REPO/android-samples/ApiDemos/kotlin
- Java:
PATH-REPO/android-samples/ApiDemos/java
- เลือกเปิด Android Studio จะสร้างโปรเจ็กต์โดยใช้เครื่องมือบิลด์ Gradle
- สร้างไฟล์
secrets.properties
ว่างในไดเรกทอรีเดียวกับไฟล์ local.properties
ของโปรเจ็กต์ ดูข้อมูลเพิ่มเติมได้ที่เพิ่มคีย์ API ลงในโปรเจ็กต์
เพิ่มสตริงต่อไปนี้ลงใน secrets.properties
โดยแทนที่ YOUR_API_KEY ด้วยค่าของคีย์ API
MAPS_API_KEY=YOUR_API_KEY
- เรียกใช้แอป
แอปตัวอย่างสําหรับแผนที่ใน Wear OS
แอปตัวอย่างสําหรับ Maps SDK สําหรับ Android ใน Wear OS พร้อมให้ใช้งานใน GitHub ซึ่งคุณใช้เป็นจุดเริ่มต้นในการสร้างแอปที่สวมใส่ได้ แอปตัวอย่างจะแสดงวิธีตั้งค่า Google Maps พื้นฐานใน Wear OS
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-02-25 UTC
[null,null,["อัปเดตล่าสุด 2025-02-25 UTC"],[[["This page provides access to the Maps SDK for Android sample code and apps, including a comprehensive ApiDemos app containing various map feature examples."],["Developers 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."],["The ApiDemos app showcases key features such as basic maps, markers, events, polylines, polygons, and My Location, with code samples readily available for use."],["Troubleshooting guidance is provided if the map doesn't display, directing users to verify their API key configuration."],["A separate sample app specifically for Wear OS is available on GitHub, demonstrating how to integrate Google Maps into wearable applications."]]],["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"]]