// 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)}}}}
[null,null,["上次更新時間:2025-08-17 (世界標準時間)。"],[],[],null,["Basic Place Autocomplete component\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\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\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\nSwift \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#example).\n\nCustomize the Basic Autocomplete component\n\nList 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\nLocation 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\nAdd 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\nSwift \n\n```swift\nlet uiCustomization = AutocompleteUICustomization(\n listDensity: .multiLine,\n listItemIcon: .noIcon,\n)\n```\n\nExample **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\nSwift \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```"]]