Places Android KTX คือชุดส่วนขยาย Kotlin สำหรับ Places SDK สำหรับ Android ส่วนขยายเหล่านี้มีฟีเจอร์ภาษา Kotlin ที่ช่วยให้คุณเขียนโค้ด Kotlin ที่กระชับและเป็นสำนวนเมื่อพัฒนาสำหรับ Places SDK สำหรับ Android Places KTX เป็นโอเพนซอร์สและพร้อมใช้งานใน GitHub พร้อมตัวอย่าง
ติดตั้ง KTX สำหรับ Places SDK
หากต้องการติดตั้ง KTX สำหรับ Places SDK สำหรับ Android ให้เพิ่มการพึ่งพาต่อไปนี้ลงในไฟล์ build.gradle.kts ระดับแอป
dependencies { // Modern Android projects use version catalogs to manage dependencies. To include the Places SDK for Android, // first add the following to your gradle/libs.versions.toml file: // // [versions] // places = "5.3.0" // // [libraries] // places = { group = "com.google.android.libraries.places", name = "places", version.ref = "places" } // // Places SDK for Android (Kotlin extensions and coroutines are built directly into the Places SDK) implementation(libs.places) // If your project does not use a version catalog, you can use the following dependency instead: // // implementation("com.google.android.libraries.places:places:5.3.0") }
ลองใช้แอปพลิเคชันตัวอย่าง
ที่เก็บข้อมูลของ GitHub สำหรับไลบรารีนี้ยังมีแอปพลิเคชัน เดโม ที่แสดงวิธีใช้ไลบรารี Places KTX ในแอปของคุณเอง
![]() |
![]() |
หากต้องการลองใช้แอปพลิเคชันเดโม ให้ทำตามขั้นตอนต่อไปนี้
- โคลนหรือดาวน์โหลดไฟล์ ZIP จาก GitHub
- ใน Android Studio ให้เลือกไฟล์ -> เปิด แล้วไปที่ ไดเรกทอรีและเปิดโฟลเดอร์ที่คุณเพิ่งโคลนหรือดาวน์โหลด
- เพิ่มคีย์ API ลงในแอปเดโม
- รับคีย์ Places API
- สร้างไฟล์ชื่อ
secrets.propertiesในไดเรกทอรีราก ไฟล์นี้ไม่ควรอยู่ภายใต้การควบคุมเวอร์ชัน เพื่อปกป้องคีย์ API - เพิ่มบรรทัดเดียวนี้ลงใน
secrets.properties
โดยPLACES_API_KEY="YOUR_API_KEY"
YOUR_API_KEYคือคีย์ API จริงที่คุณได้รับใน ขั้นตอนแรก คุณดูlocal.defaults.propertiesเป็นตัวอย่างได้ - เลือกโมดูล app-places-ktx ในการกำหนดค่าการเรียกใช้
- เลือกเรียกใช้ 'app-places-ktx'

