يتيح لك مكوّن "الإكمال التلقائي الأساسي للأماكن" في Places UI Kit إضافة مكوّن فردي لواجهة المستخدم يعرض رقم تعريف مكان عندما يختار المستخدم مكانًا. المكوّن عبارة عن غطاء بملء الشاشة يوفّر شريط بحث للمستخدمين لإدخال طلب بحث. أثناء الكتابة، ستظهر قائمة بنتائج الإكمال التلقائي أسفل شريط البحث. عندما ينقر المستخدم على مكان، يتم عرض عنصر مكان يتضمّن معرّف المكان فقط للمطوّر. هذا المكوِّن قابل للتخصيص.
يتلقّى المكوّن حدودًا جغرافية ومَعلمات بحث أخرى من خلال البنية AutocompleteFilter.
تقدّم الاستجابة بنية Place مع ملء الحقل placeID فقط.
يتضمّن مكوّن "الإكمال التلقائي للأماكن" الأساسي خيارات التخصيص التالية: كثافة القائمة، وما إذا كان سيتم تضمين رموز المواقع الجغرافية. استخدِم بنية AutocompleteUICustomization لتخصيص المكوّن.
يمكنك استخدام مكوّن "الإكمال التلقائي للأماكن" الأساسي بشكل مستقل أو بالاشتراك مع واجهات برمجة التطبيقات والخدمات الأخرى في Google Maps Platform.
الفوترة
يتم تحصيل رسوم منك في كل مرة يتم فيها فتح المكوّن وإجراء طلب بحث. لن يتم تحصيل رسوم منك مرة أخرى مقابل هذه الجلسة ما لم تنتهِ صلاحية الجلسة أو يتم اختيار مكان من القائمة.
إضافة مكوّن "الإكمال التلقائي الأساسي" إلى تطبيقك
اضبط مَعلمات فلتر الإكمال التلقائي (مثل الأنواع المطلوب عرضها والبلد الذي يجب حصر النتائج فيه وإحداثيات المنطقة للنتائج ومعلومات المسافة في حال ضبط مصدر المستخدم) كما تفعل لاستخدام Place Autocomplete (New) بدون Places UI Kit. راجِع مستندات Place Autocomplete (New) للحصول على التعليمات الكاملة ومثال على الرمز البرمجي لإنشاء فلتر إكمال تلقائي.
يمكنك اختيار عرض قائمة من سطرَين أو قائمة متعدّدة الأسطر. استخدِم الخيارات في AutocompleteListDensity (.twoLine أو .multiLine) في الفئة AutocompleteUICustomization. إذا لم تحدّد كثافة القائمة، سيعرض المكوّن قائمة من سطرَين.
رمز الموقع الجغرافي
يمكنك اختيار ما إذا كنت تريد عرض رمز مكان تلقائي في قائمة النتائج. استخدِم الخيارات في AutocompleteUIIcon (.defaultIcon أو .noIcon) في الفئة AutocompleteUICustomization.
إضافة تخصيصات إلى مكوّن "الإكمال التلقائي الأساسي"
ينشئ هذا المثال مكوّن "الإكمال التلقائي الأساسي" المخصّص مع زر. تم اختيار الرمز التلقائي وكثافة القائمة المكوّنة من سطرَين. تم ضبط فلتر الإكمال التلقائي للعثور على أماكن ذات صلة بالمحاسبة في لاس فيغاس والمناطق المجاورة لها.
Swift
// Note: You must provide an API key in your app entry point first.// A demo view of the basic place autocomplete widget.publicstructBasicPlaceAutocompleteView:View{@StateprivatevarfetchedPlace:Place?@StateprivatevarplacesError:PlacesError?@StateprivatevarshowWidget=falsepublicvarbody:someView{lettypes:Set<PlaceType>=[.accounting]letcountries:Set<String>=["US"]letorigin=CLLocation(latitude:36.19030535579595,longitude:-115.25397680618019)letcoordinateRegion=RectangularCoordinateRegion(northEast:CLLocationCoordinate2D(latitude:36.25290087640495,longitude:-115.08025549571225),southWest:CLLocationCoordinate2D(latitude:36.06607422287787,longitude:-115.33431432920293))letregionCode="US"letinputOffset=10letfilter=AutocompleteFilter(types:types,countries:countries,origin:origin,coordinateRegionBias:coordinateRegion,regionCode:regionCode)letuiCustomization=AutocompleteUICustomization(listDensity:.multiLine,listItemIcon:.noIcon)VStack{Button("Search for a place"){showWidget.toggle()}.basicPlaceAutocomplete(filter:filter,uiCustomization:uiCustomization??AutocompleteUICustomization(),show:$showWidget,onSelection:{placeinguardletplaceID=place.placeIDelse{self.placesError=.internal("Could not fetch place details because place ID from selected suggestion not found.")return}Task{letplacesClient=awaitPlacesClient.sharedletfetchPlaceRequest=FetchPlaceRequest(placeID:placeID,placeProperties:[.displayName,.formattedAddress])switchawaitplacesClient.fetchPlace(with:fetchPlaceRequest){case.success(letplace):print("Fetched place: \(place)")self.fetchedPlace=placecase.failure(letplacesError):print("Failed to fetch place: \(placesError)")self.placesError=placesError}}},onError:{placesErrorinself.placesError=placesError})ifletplacesError=$placesError.wrappedValue{Text(placesError.localizedDescription).frame(maxWidth:.infinity,alignment:.leading)}elseifletfetchedPlace=$fetchedPlace.wrappedValue{Text("\(fetchedPlace)").frame(maxWidth:.infinity,alignment:.leading)}}}}
تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],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/ios-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 component takes geographic bounds and other search parameters through the [`AutocompleteFilter`](/maps/documentation/places/ios-sdk/reference/swift/Structs/AutocompleteFilter) struct.\n\n\nThe response provides a [`Place`](/maps/documentation/places/ios-sdk/reference/swift/Structs/Place) struct with only the `placeID` field populated.\n\n\nThe Basic Place Autocomplete component has the following customization options: list density, and whether to include location icons. Use the [`AutocompleteUICustomization`](https://developers.google.com/maps/documentation/places/ios-sdk/reference/swift/Structs/AutocompleteUICustomization) struct 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, and distance information if the users origin is set) as you would to use Place Autocomplete (New) without the Places UI Kit. See [the Place Autocomplete (New) documentation](/maps/documentation/places/ios-sdk/place-autocomplete) for full instructions and [an example of the code to create an autocomplete filter](/maps/documentation/places/ios-sdk/place-autocomplete#optional-parameters).\n\n\nOnce you've created your autocomplete filter, you can create a struct with your UI customizations. [See customization options and instructions](/maps/documentation/places/ios-sdk/basic-place-autocomplete#customize-the-basic-autocomplete-component).\n\n\nThen, create a button that will launch your customized Basic Autocomplete component. \n\n### Swift\n\n```swift\n Button(\"Search for a place\") {\n showWidget.toggle()\n }\n .basicPlaceAutocomplete(\n show: $showWidget\n // ...\n )\n```\n\n\n[See the full example](/maps/documentation/places/ios-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` (`.twoLine` or `.multiLine`) in the [`AutocompleteUICustomization`](/maps/documentation/places/ios-sdk/reference/swift/Structs/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` (`.defaultIcon` or `.noIcon`) in the [`AutocompleteUICustomization`](/maps/documentation/places/ios-sdk/reference/swift/Structs/AutocompleteUICustomization) class.\n\n### Add customizations to the Basic Autocomplete component\n\n\nUse the [`AutocompleteUICustomization`](/maps/documentation/places/ios-sdk/reference/swift/Structs/AutocompleteUICustomization) class to customize the Basic Autocomplete component. \n\n### Swift\n\n```swift\nlet uiCustomization = AutocompleteUICustomization(\n listDensity: .multiLine,\n listItemIcon: .noIcon,\n)\n```\n\nExample\n-------\n\n| **Important:** Set the initial value of `showWidget` to false in order to have your customized component appear when the user clicks the button.\n\n\nThis example creates a custom Basic Autocomplete component with a button. The default icon and two-line list density have been selected. The autocomplete filter is set to find accounting-related Places in and near Las Vegas. \n\n### Swift\n\n```swift\n // Note: You must provide an API key in your app entry point first.\n // A demo view of the basic place autocomplete widget.\n public struct BasicPlaceAutocompleteView: View {\n @State private var fetchedPlace: Place?\n @State private var placesError: PlacesError?\n @State private var showWidget = false\n public var body: some View {\n let types: Set\u003cPlaceType\u003e = [.accounting]\n let countries: Set\u003cString\u003e = [\"US\"]\n let origin = CLLocation(latitude: 36.19030535579595, longitude: -115.25397680618019)\n let coordinateRegion = RectangularCoordinateRegion(\n northEast: CLLocationCoordinate2D(\n latitude: 36.25290087640495, longitude: -115.08025549571225),\n southWest: CLLocationCoordinate2D(latitude: 36.06607422287787, longitude: -115.33431432920293)\n )\n let regionCode = \"US\"\n let inputOffset = 10\n let filter = AutocompleteFilter(\n types: types,\n countries: countries,\n origin: origin,\n coordinateRegionBias: coordinateRegion,\n regionCode: regionCode)\n let uiCustomization = AutocompleteUICustomization(\n listDensity: .multiLine,\n listItemIcon: .noIcon)\n VStack {\n Button(\"Search for a place\") {\n showWidget.toggle()\n }\n .basicPlaceAutocomplete(\n filter: filter,\n uiCustomization: uiCustomization ?? AutocompleteUICustomization(),\n show: $showWidget,\n onSelection: { place in\n guard let placeID = place.placeID else {\n self.placesError = .internal(\n \"Could not fetch place details because place ID from selected suggestion not found.\"\n )\n return\n }\n Task {\n let placesClient = await PlacesClient.shared\n let fetchPlaceRequest = FetchPlaceRequest(\n placeID: placeID,\n placeProperties: [.displayName, .formattedAddress]\n )\n switch await placesClient.fetchPlace(with: fetchPlaceRequest) {\n case .success(let place):\n print(\"Fetched place: \\(place)\")\n self.fetchedPlace = place\n case .failure(let placesError):\n print(\"Failed to fetch place: \\(placesError)\")\n self.placesError = placesError\n }\n }\n },\n onError: { placesError in\n self.placesError = placesError\n }\n )\n if let placesError = $placesError.wrappedValue {\n Text(placesError.localizedDescription)\n .frame(maxWidth: .infinity, alignment: .leading)\n } else if let fetchedPlace = $fetchedPlace.wrappedValue {\n Text(\"\\(fetchedPlace)\")\n .frame(maxWidth: .infinity, alignment: .leading)\n }\n }\n }\n }\n```"]]