Places UI Kit의 기본 Place Autocomplete 구성요소를 사용하면 사용자가 장소를 선택할 때 장소 ID를 반환하는 개별 UI 구성요소를 추가할 수 있습니다. 이 구성요소는 사용자가 검색어를 입력할 수 있는 검색창을 제공하는 전체 화면 커버입니다. 사용자가 입력하면 검색창 아래에 자동 완성 결과 목록이 표시됩니다. 사용자가 장소를 탭하면 장소 ID만 있는 장소 객체가 개발자에게 반환됩니다. 이 구성요소는 맞춤설정할 수 있습니다.
기본 장소 자동 완성 구성요소에는 목록 밀도와 위치 아이콘 포함 여부라는 맞춤설정 옵션이 있습니다. AutocompleteUICustomization 구조체를 사용하여 구성요소를 맞춤설정합니다.
기본 장소 자동 완성 구성요소는 독립적으로 사용하거나 다른 Google Maps Platform API 및 서비스와 함께 사용할 수 있습니다.
결제
구성요소가 열리고 쿼리가 실행될 때마다 요금이 청구됩니다. 세션이 만료되거나 목록에서 장소를 선택하지 않는 한 해당 세션에 대해 다시 청구되지 않습니다.
앱에 기본 자동 완성 구성요소 추가
Places UI Kit 없이 Place Autocomplete (New)을 사용하는 것과 마찬가지로 자동 완성 필터 매개변수 (예: 반환할 유형, 결과를 제한할 국가, 결과의 지역 좌표, 사용자 출발지가 설정된 경우 거리 정보)를 설정합니다. 전체 안내와 자동 완성 필터를 만드는 코드 예시는 Place Autocomplete (신규) 문서를 참고하세요.
2줄 목록 또는 여러 줄 목록을 표시할 수 있습니다. AutocompleteUICustomization 클래스에서 AutocompleteListDensity (.twoLine 또는 .multiLine)의 옵션을 사용합니다. 목록 밀도를 지정하지 않으면 구성요소에 2줄 목록이 표시됩니다.
위치 아이콘
결과 목록에 기본 장소 아이콘을 표시할지 선택할 수 있습니다. AutocompleteUICustomization 클래스에서 AutocompleteUIIcon (.defaultIcon 또는 .noIcon)의 옵션을 사용합니다.
이 예시에서는 버튼이 있는 맞춤 기본 자동 완성 구성요소를 만듭니다. 기본 아이콘과 2줄 목록 밀도가 선택되었습니다. 자동 완성 필터는 라스베이거스 및 그 주변에서 회계 관련 장소를 찾도록 설정되어 있습니다.
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)}}}}
[[["이해하기 쉬움","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-17(UTC)"],[],[],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```"]]