我使用官方Google Documentation创建地址查找。
在Android版本中,我可以将结果偏向我的区域。
例如,输入“123 Main St”会先显示我所在城镇的Main,然后再显示其他结果。
在iOS中,我无法弄清楚如何做到这一点。我正在使用GMSAutocompleteViewController
代表的“添加全屏控制”。
有一个GMSCoordinateBounds
,但示例是针对地图的。我没有使用地图。
我已经用这样的东西修补了但却无法让它发挥作用。我是否走在正确的轨道上?
- (void) placeAutocomplete : (NSString*) location : Bounds:(GMSCoordinateBounds *)bounds{
[_placesClient autocompleteQuery:location
bounds:bounds
filter:filter
callback:^(NSArray *results, NSError *error) {
if (error != nil) {
NSLog(@"Autocomplete error %@", [error localizedDescription]);
return;
}
for (GMSAutocompletePrediction* result in results) {
NSLog(@"Result '%@' with placeID %@", result.attributedFullText.string, result.placeID);
}
}];
}
有任何帮助吗?
答案 0 :(得分:2)
您可以直接在GMSAutocompleteViewController
上设置界限,例如:
// Present the Autocomplete view controller when the button is pressed.
@IBAction func autocompleteClicked(_ sender: UIButton) {
let autocompleteController = GMSAutocompleteViewController()
autocompleteController.delegate = self
// Set bounds to inner-west Sydney Australia.
let neBoundsCorner = CLLocationCoordinate2D(latitude: -33.843366,
longitude: 151.134002)
let swBoundsCorner = CLLocationCoordinate2D(latitude: -33.875725,
longitude: 151.200349)
let bounds = GMSCoordinateBounds(coordinate: neBoundsCorner,
coordinate: swBoundsCorner)
autocompleteController.bounds = bounds
present(autocompleteController, animated: true, completion: nil)
}
答案 1 :(得分:0)
根据您的位置创建界限,并将其设置为 GMSAutocompleteViewController
func presentAddressFinder(){
let autocompleteController = GMSAutocompleteViewController()
autocompleteController.delegate = self
let bounds = GMSCoordinateBounds()
autocompleteController.autocompleteBounds = bounds.includingCoordinate(currentLocation)
present(autocompleteController, animated: true, completion: nil)
}
此处currentLocation
是CLLocationCoordinate2D!