Thành phần Cơ bản của tính năng Tự động hoàn thành địa điểm trong Places UI Kit cho phép bạn thêm một thành phần giao diện người dùng riêng lẻ trả về một mã địa điểm khi người dùng chọn một địa điểm. Thành phần này là một lớp phủ toàn màn hình cung cấp thanh tìm kiếm để người dùng nhập cụm từ tìm kiếm. Khi người dùng nhập nội dung, một danh sách kết quả tự động hoàn thành sẽ xuất hiện bên dưới thanh tìm kiếm. Khi người dùng nhấn vào một địa điểm, một đối tượng địa điểm chỉ có mã địa điểm sẽ được trả về cho nhà phát triển. Bạn có thể tuỳ chỉnh thành phần này.
Thành phần Basic Place Autocomplete có các lựa chọn tuỳ chỉnh sau: mật độ danh sách và có bao gồm biểu tượng vị trí hay không. Dùng AutocompleteUICustomization để tuỳ chỉnh thành phần.
Bạn có thể sử dụng thành phần Basic Place Autocomplete một cách độc lập hoặc kết hợp với các API và dịch vụ khác của Google Maps Platform.
Thanh toán
Bạn sẽ bị tính phí mỗi khi thành phần được mở và một truy vấn được thực hiện. Bạn sẽ không bị tính phí lại cho phiên đó, trừ phi phiên hết hạn hoặc bạn chọn một địa điểm trong danh sách.
Thêm thành phần Basic Autocomplete vào ứng dụng
Đặt các thông số bộ lọc tự động hoàn thành (ví dụ: các loại cần trả về, quốc gia cần giới hạn kết quả, toạ độ khu vực cho kết quả, nguồn gốc của yêu cầu hiển thị thông tin khoảng cách, nếu có) như khi bạn sử dụng tính năng Tự động hoàn thành địa điểm (Mới) mà không cần Places UI Kit. Hãy xem tài liệu về tính năng Tự động hoàn thành địa điểm (Mới) để biết hướng dẫn đầy đủ và ví dụ về mã để tạo bộ lọc tự động hoàn thành.
Bạn có thể chọn hiển thị danh sách gồm 2 dòng hoặc danh sách nhiều dòng. Sử dụng các lựa chọn trong AutocompleteListDensity (TWO_LINE hoặc MULTI_LINE) trong lớp AutocompleteUICustomization. Nếu bạn không chỉ định mật độ danh sách, thành phần sẽ hiển thị danh sách gồm 2 dòng.
Biểu tượng vị trí
Bạn có thể chọn hiển thị biểu tượng địa điểm mặc định trên danh sách kết quả hay không. Sử dụng các lựa chọn trong AutocompleteUIIcon (listItemDefaultIcon hoặc noIcon) trong lớp AutocompleteUICustomization.
Thêm các chế độ tuỳ chỉnh vào thành phần Tự động hoàn thành cơ bản
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-08-30 UTC."],[],[],null,["Select platform: [Android](/maps/documentation/places/android-sdk/basic-place-autocomplete-ui-kit \"View this page for the Android platform docs.\") [iOS](/maps/documentation/places/ios-sdk/basic-place-autocomplete-ui-kit \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/places-ui-kit/basic-autocomplete \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\nBasic Place Autocomplete component\n==================================\n\n\nThe Basic Place Autocomplete component of the Places UI Kit lets you add an individual UI component that returns a [place ID](/maps/documentation/places/android-sdk/place-id) when a user selects a place. The component is a full screen cover that provides a search bar for users to enter a query. As the user types, a list of autocomplete results will be shown below the search bar. When the user taps on a place, a place object with only place ID is returned to the developer. This component is customizable.\n\n\nThe Basic Place Autocomplete component has the following customization options: list density, and whether to include location icons. Use [`AutocompleteUICustomization`](/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/widget/model/AutocompleteUiCustomization) to customize the component.\n\n\nYou can use the Basic Place Autocomplete component independently or in conjunction with other Google Maps Platform APIs and services.\n\nBilling\n-------\n\n\nYou are billed each time the component is opened and a query is made. You won't be billed again for that session unless the session expires or a place is selected from the list.\n\nAdd the Basic Autocomplete component to your app\n------------------------------------------------\n\n\nSet the autocomplete filter parameters (for example, the types to return, the country to limit results to, the region coordinates for results, the origin of the request to display distance information, if available) as you would to use Place Autocomplete (New) without the Places UI Kit. See the [Place Autocomplete (New) documentation](/maps/documentation/places/android-sdk/place-autocomplete) for full instructions and [an example of the code to create an autocomplete filter](/maps/documentation/places/android-sdk/place-autocomplete#optional-parameters).\n\n\nOnce you've created your autocomplete filter, add your UI customizations. [See customization options and instructions.](/maps/documentation/places/android-sdk/basic-place-autocomplete#customize-the-basic-autocomplete-component) \n\n### Kotlin\n\n```kotlin\nAutocompleteUiCustomization.create(\n listDensity = AutocompleteListDensity.MULTI_LINE,\n listItemIcon = AutocompleteUiIcon.noIcon(),\n)\n```\n\n### Java\n\n```java\n \nAutocompleteUiCustomization.builder()\n .listItemIcon(AutocompleteUiIcon.noIcon())\n .listDensity(AutocompleteListDensity.MULTI_LINE)\n .build()\n```\n\n\n[See the full example](/maps/documentation/places/android-sdk/basic-place-autocomplete-ui-kit#example).\n\nCustomize the Basic Autocomplete component\n------------------------------------------\n\n### List density\n\n\nYou can choose to either display a two-line list or a multiline list. Use the options in `AutocompleteListDensity` (`TWO_LINE` or `MULTI_LINE`) in the [`AutocompleteUICustomization`](/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/widget/model/AutocompleteUiCustomization) class. If you don't specify the list density, the component will display a two-line list.\n\n### Location icon\n\n\nYou can choose whether to display a default place icon on the results list. Use the options in `AutocompleteUIIcon` (`listItemDefaultIcon` or `noIcon`) in the [`AutocompleteUICustomization`](/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/widget/model/AutocompleteUiCustomization) class.\n\n### Add customizations to the Basic Autocomplete component\n\n\nUse the [`AutocompleteUICustomization`](/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/widget/model/AutocompleteUiCustomization) class to customize the Basic Autocomplete component. \n\n### Kotlin\n\n```kotlin\n.setAutocompleteUiCustomization(\n AutocompleteUiCustomization.create(\n listDensity = AutocompleteListDensity.MULTI_LINE,\n listItemIcon = AutocompleteUiIcon.noIcon(),\n )\n)\n```\n\n### Java\n\n```java\n.setAutocompleteUiCustomization(\n AutocompleteUiCustomization.builder()\n .listItemIcon(AutocompleteUiIcon.noIcon())\n .listDensity(AutocompleteListDensity.MULTI_LINE)\n .build()\n)\n```\n\nExample\n-------\n\n\nThis example creates a custom Basic Autocomplete component. \n\n### Kotlin\n\n```kotlin\n val basicPlaceAutocompleteActivityResultLauncher:\n ActivityResultLauncher\u003cIntent\u003e =\n registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {\n result: ActivityResult -\u003e\n val intent = result.data\n val place: Place? = BasicPlaceAutocomplete.getPlaceFromIntent(intent!!)\n val status: Status? = \n BasicPlaceAutocomplete.getResultStatusFromIntent(intent!!)\n // ...\n }\n \n val autocompleteIntent: Intent =\n BasicPlaceAutocomplete.createIntent(this) {\n setInitialQuery(\"INSERT_QUERY_TEXT\")\n setOrigin(LatLng(10.0, 10.0))\n // ...\n \n setAutocompleteUiCustomization(\n AutocompleteUiCustomization.create(\n listDensity = AutocompleteListDensity.MULTI_LINE,\n listItemIcon = AutocompleteUiIcon.noIcon(),\n )\n )\n }\n \n basicPlaceAutocompleteActivityResultLauncher.launch(autocompleteIntent)\n```\n\n### Java\n\n```java\n ActivityResultLauncher\u003cIntent\u003e basicPlaceAutocompleteActivityResultLauncher =\n registerForActivityResult(\n new ActivityResultContracts.StartActivityForResult(),\n new ActivityResultCallback\u003cActivityResult\u003e() {\n @Override\n public void onActivityResult(ActivityResult result) {\n Intent intent = result.getData();\n if (intent != null) {\n Place place =\n BasicPlaceAutocomplete.getPlaceFromIntent(intent);\n Status status =\n BasicPlaceAutocomplete.getResultStatusFromIntent(intent);\n //...\n }\n }\n }\n );\n \n Intent basicPlaceAutocompleteIntent =\n new BasicPlaceAutocomplete.IntentBuilder()\n .setInitialQuery(\"INSERT_QUERY_TEXT\")\n .setOrigin(new LatLng(10.0, 10.0))\n //...\n \n .setAutocompleteUiCustomization(\n AutocompleteUiCustomization.builder()\n .listItemIcon(AutocompleteUiIcon.noIcon())\n .listDensity(AutocompleteListDensity.MULTI_LINE)\n .build())\n .build(this);\n \n basicPlaceAutocompleteActivityResultLauncher.launch(basicPlaceAutocompleteIntent);\n```"]]