Địa điểm Tổng quan và thiết lập KTX của Android
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Places Android KTX là một tập hợp các tiện ích Kotlin cho Places SDK for Android. Các tiện ích này cung cấp các tính năng ngôn ngữ Kotlin, cho phép bạn viết mã Kotlin ngắn gọn và tự nhiên khi phát triển cho Places SDK for Android.
Places KTX là nguồn mở và có trên GitHub cùng với các ví dụ.
Cài đặt KTX cho Places SDK
Để cài đặt KTX cho Places SDK for Android, hãy thêm các phần phụ thuộc sau vào tệp build.gradle.kts
cấp ứng dụng.
dependencies {
// KTX for the Places SDK for Android library
implementation("com.google.maps.android:places-ktx:3.3.1")
}
Dùng thử ứng dụng mẫu
Kho lưu trữ GitHub cho thư viện này cũng chứa một ứng dụng minh hoạ cho biết cách bạn có thể sử dụng thư viện Places KTX trong ứng dụng của riêng mình.
Để dùng thử ứng dụng minh hoạ, hãy làm theo các bước sau:
- Trên GitHub, hãy sao chép hoặc tải tệp ZIP xuống.
- Trong Android Studio, hãy chọn File (Tệp) -> Open (Mở) rồi chuyển đến thư mục và mở thư mục mà bạn vừa sao chép hoặc tải xuống.
- Thêm khoá API vào ứng dụng minh hoạ.
- Lấy khoá Places API.
- Trong thư mục gốc, hãy tạo một tệp có tên là
secrets.properties
. Tệp này KHÔNG được nằm trong chế độ kiểm soát phiên bản để bảo vệ khoá API của bạn.
- Thêm dòng đơn này vào
secrets.properties
PLACES_API_KEY="YOUR_API_KEY"
trong đó YOUR_API_KEY
là khoá API thực tế mà bạn đã nhận được ở bước đầu tiên. Bạn có thể xem local.defaults.properties
làm ví dụ.
- Trong cấu hình chạy, hãy chọn mô-đun app-places-ktx.
- Chọn Run 'app-places-ktx'. (Chạy 'app-places-ktx').
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-09-04 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-09-04 UTC."],[[["\u003cp\u003ePlaces Android KTX offers Kotlin extensions for streamlined Places SDK interaction using idiomatic Kotlin.\u003c/p\u003e\n"],["\u003cp\u003eNative Kotlin APIs within the Places SDK for Android (version 4.0.0 and later) can be used as an alternative to Places Android KTX extensions.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can easily integrate Places KTX by adding the specified dependency to their app's \u003ccode\u003ebuild.gradle.kts\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eA demo application within the GitHub repository provides practical examples of utilizing the Places KTX library.\u003c/p\u003e\n"]]],["Places KTX provides Kotlin extensions for the Places SDK for Android, enabling concise Kotlin development. Install it by adding the `com.google.maps.android:places-ktx:3.3.1` dependency to your app's `build.gradle.kts` file. A demo app is available on GitHub; to run it, clone the repository, obtain a Places API key, and store it in a `secrets.properties` file in the root directory. Select and Run the **app-places-ktx** module in Android Studio. The Places SDK also offers native Kotlin APIs as of version 4.0.0.\n"],null,["# Places Android KTX Overview and Setup\n\nPlaces Android KTX is a collection of Kotlin extensions for the\nPlaces SDK for Android. These extensions provide Kotlin\nlanguage features that enable you to write concise and idiomatic Kotlin when\ndeveloping for the Places SDK for Android.\nPlaces KTX is open-sourced and available on\n[GitHub](https://github.com/googlemaps/android-places-ktx)\nalong with examples.\n| **Note:** As of [version\n| 4.0.0](/maps/documentation/places/android-sdk/release-notes), the Places SDK for Android includes native Kotlin APIs that can be used instead of the Places Android KTX extensions. For more information, see the Places SDK for Android [Reference\n| Overview](/maps/documentation/places/android-sdk/reference).\n\nInstall KTX for the Places SDK\n------------------------------\n\nTo install KTX for the Places SDK for Android, add the\nfollowing dependencies to your app-level `build.gradle.kts` file. \n\n```carbon\ndependencies {\n\n // KTX for the Places SDK for Android library\n implementation(\"com.google.maps.android:places-ktx:3.3.1\")\n}\n```\n\nTry the sample application\n--------------------------\n\nThe GitHub repository for this library also contains a [demo\napplication](https://github.com/googlemaps/android-places-ktx)\nthat shows how you can use the Places KTX library in your own app.\n\n|---|---|\n| | |\n\nTo try the demo application, follow these steps:\n\n1. From [GitHub](https://github.com/googlemaps/android-places-ktx), clone the or download the ZIP file.\n2. In Android Studio, choose **File -\\\u003e Open** and navigate to the directory and open the folder that you just cloned or downloaded.\n3. Add an API key to the demo app.\n 1. [Get a Places API key](/maps/documentation/places/android-sdk/get-api-key).\n 2. In the root directory, create a file called `secrets.properties`. This file should NOT be under version control to protect your API key.\n 3. Add this single line to `secrets.properties` \n\n ```\n PLACES_API_KEY=\"YOUR_API_KEY\"\n ```\n where `YOUR_API_KEY` is the actual API key you obtained in the first step. You can look at the [`local.defaults.properties`](https://github.com/googlemaps/android-places-ktx/blob/main/local.defaults.properties) as an example.\n4. Under the run configuration, select the module **app-places-ktx**.\n5. Select **Run 'app-places-ktx'.**"]]