Places SDK for iOS 支援現有的 Place Autocomplete。 如果您熟悉 Place Autocomplete (新版) Place Autocomplete 進行下列變更:
使用新的定價模式。如需所有 API 的定價資訊,請參閱 Places SDK for iOS 定價 (新版)。
如要提出要求,請呼叫新的
GMSPlacesClient fetchAutocompleteSuggestionsFromRequest:
敬上 方法。傳遞至要求:
新的
GMSAutocompleteRequest
敬上 類別,用來定義所有請求參數,例如查詢和 工作階段符記型別的回呼
GMSAutocompleteSuggestionsCallback
敬上 處理回應。
GMSAutocompleteFilter
敬上 課程現在可讓您:- 設定用來決定結果格式的區碼。
- 設定預測偏移量,亦即 Unicode 字元偏移 。
回應是由新的
GMSAutocompleteSuggestion
敬上 類別此類別包含新型別的執行個體陣列GMSAutocompletePlaceSuggestion
敬上 代表建議工作階段結束時,如果 Place Details (新功能) 或 地址驗證。適用對象 如需更多資訊,請參閱 Autocomplete (新版) 和工作階段價格:
要求範例
使用 Place Autocomplete (新版) 時,發出要求並
傳遞 GMSAutocompleteRequest
執行個體中的所有參數:
Swift
let token = GMSAutocompleteSessionToken()
let northEastBounds = CLLocationCoordinate2DMake(37.38816277477739, -122.08813770258874)
let southWestBounds = CLLocationCoordinate2DMake(37.39580487866437, -122.07702325966572)
let filter = GMSAutocompleteFilter()
filter.types = [kGMSPlaceTypeRestaurant]
filter.locationBias = GMSPlaceRectangularLocationOption(northEastBounds, southWestBounds)
let request = GMSAutocompleteRequest(query:"Sicilian piz")
request.filter = filter
request.sessionToken = token
GMSPlacesClient.shared().fetchAutocompleteSuggestions(from: request, callback: { results, error in
// Handle response
})
Objective-C
CLLocationCoordinate2D northEast = CLLocationCoordinate2DMake(37.38816277477739, -122.08813770258874);
CLLocationCoordinate2D southWest = CLLocationCoordinate2DMake(37.39580487866437, -122.07702325966572);
GMSAutocompleteFilter *filter = [[GMSAutocompleteFilter alloc] init];
filter.types = @[ kGMSPlaceTypeRestaurant ];
filter.locationBias = GMSPlaceRectangularLocationOption(northEast, southWest);
GMSAutocompleteRequest *request = [[GMSAutocompleteRequest alloc] initWithQuery:@"Sicilian piz"];
request.sessionToken = token;
request.filter = filter;
[[GMSPlacesClient sharedClient] fetchAutocompleteSuggestionsFromRequest:request callback:^(NSArray<GMSAutocompleteSuggestion *> * results, NSError * error){
// Handle response
for (GMSAutocompleteSuggestion *suggestion in results) {
if (suggestion.placeSuggestion) {
// Show place suggestion data.
}
}
}];