我正在使用谷歌地方iOS SDK来搜索附近的地方。我通过Xcode在我的设备上模拟了丹佛的位置。但在搜索" 星巴克"时,我期待看到" 星巴克,3110 E 1st Ave,Denver,CO 80206 &# 34;在列表中。但我不是。只有当我用" 星巴克,3110 E "进行搜索时,我才能看到它。以下是使用
的代码 CLLocation *userLocation = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
GMSAutocompleteFilter *filter = [[GMSAutocompleteFilter alloc] init];
filter.type = kGMSPlacesAutocompleteTypeFilterNoFilter;
GMSAutocompleteViewController *acController = [[GMSAutocompleteViewController alloc] init];
acController.delegate = self;
acController.autocompleteFilter.type = kGMSPlacesAutocompleteTypeFilterNoFilter;
CLLocationCoordinate2D newLocation = [self locationWithBearing:userLocation.course distance:30000.0 fromLocation:userLocation.coordinate];
acController.autocompleteBounds = [[GMSCoordinateBounds alloc]initWithCoordinate:userLocation.coordinate coordinate:newLocation];
新位置的计算范围为距离用户位置30英里。
如果我做错了,请纠正我。
答案 0 :(得分:0)
您必须为附近的地点提供界限。
func openPlacePicker(){
let acController = GMSAutocompleteViewController()
let neBoundsCorner = CLLocationCoordinate2D(latitude: (locationManager.location?.coordinate.latitude)!,
longitude: (locationManager.location?.coordinate.longitude)!)
let swBoundsCorner = CLLocationCoordinate2D(latitude: (locationManager.location?.coordinate.latitude.abs)! + 1,
longitude: (locationManager.location?.coordinate.longitude.abs)! + 1)
let bounds = GMSCoordinateBounds(coordinate: neBoundsCorner,
coordinate: swBoundsCorner)
acController.autocompleteBounds = bounds
acController.delegate = self
present(acController, animated: true, completion: nil)
}