我需要查找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; }但它返回超出此半径的结果。 任何人都可以建议如何在边界内获得结果。
I need to find out Google Places with in boundary. I have implemeted Google place autocomplete and tried to pass bounds for region. But it still gives me result that are not present in that boundaries.
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; }But it returns result that are beyond this radius. Can anyone suggest how to get result with in the boundaries.
最满意答案
您是否可以通过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];I am not sure if iOS SDK provides any option for providing radius boundary in their Google Place SDK. But I have resolved it by implementing their web API for near by search at my PHP backend.
This helps me to filter out results based on my radius.
https://developers.google.com/places/webservice/search?hl=en
更多推荐
发布评论