带有边界的iOS GMSAutoComplete结果(iOS GMSAutoComplete result with in boundaries)

编程入门 行业动态 更新时间:2024-10-27 23:20:52
带有边界的iOS GMSAutoComplete结果(iOS GMSAutoComplete result with in boundaries)

我需要查找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并以这种方式将其传递给GM​​SPlacesClient

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

更多推荐

本文发布于:2023-07-26 19:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1280244.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:边界   iOS   GMSAutoComplete   result   boundaries

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!