我需要查找Google地方信息。我已经实现了Google地方自动填充功能,并尝试传递区域边界。但它仍然给我的结果不存在于那个边界。
GMSCoordinateBounds *bounds = [self getGMSBoundsWithRadiusInMeters:20];
GMSAutocompleteFilter *filter = [[GMSAutocompleteFilter alloc] init];
filter.type = kGMSPlacesAutocompleteTypeFilterCity;
GMSPlacesClient *placeClient=[GMSPlacesClient sharedClient];
[placeClient autocompleteQuery:place
bounds:bounds
filter:filter
callback:^(NSArray *results, NSError *error) {
if (error != nil) {
NSLog(@"Autocomplete error %@", [error localizedDescription]);
return;
}
searchedPlaces=results;
UIActionSheet *actionSheet = [[UIActionSheet
alloc ]initWithTitle:@"Select Place" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:nil];
for (GMSAutocompletePrediction* result in results) {
[actionSheet addButtonWithTitle:[self getPlaceTitle:result.attributedFullText.string]];
}
[actionSheet showInView:self.view];
}];
-(GMSCoordinateBounds*)getGMSBoundsWithRadiusInMeters:(float)radius{
CLLocationCoordinate2D center=CLLocationCoordinate2DMake(28.77, 77.77);
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(center, radius*2, radius*2);
CLLocationCoordinate2D northEast = CLLocationCoordinate2DMake(region.center.latitude - region.span.latitudeDelta/2, region.center.longitude - region.span.longitudeDelta/2);
CLLocationCoordinate2D southWest = CLLocationCoordinate2DMake(region.center.latitude + region.span.latitudeDelta/2, region.center.longitude + region.span.longitudeDelta/2);
GMSCoordinateBounds* bounds = [[GMSCoordinateBounds alloc]
initWithCoordinate: northEast
coordinate: southWest];
return bounds;
}
但它会返回超出此半径的结果。任何人都可以建议如何在边界内获得结果。
答案 0 :(得分:0)
您是否可以通过CLLLocationManager获取userLocation并以这种方式将其传递给GMSPlacesClient
CLLocationCoordinate2D northEast = CLLocationCoordinate2DMake(_userLocation.latitude + 0.15, _userLocation.longitude + 0.15);
CLLocationCoordinate2D southWest = CLLocationCoordinate2DMake(_userLocation.latitude - 0.15, _userLocation.longitude - 0.15);
userBound = [[GMSCoordinateBounds alloc] initWithCoordinate:northEast
coordinate:southWest];