Google Place Api Key仅返回附近的城市

时间:2016-09-08 12:45:49

标签: ios objective-c google-places-api

我使用google place api key进行搜索引用,但它只提供附近的城市 这是代码

NSString *GoogleURL = [NSString stringWithFormat:@"%https://maps.googleapis.com/maps/api/place/cities/json"];
    NSDictionary *param = @{@"location":[NSString stringWithFormat:@"%f,%f",sharedManager.currentLocation.coordinate.latitude,sharedManager.currentLocation.coordinate.longitude],
                            @"radius":@(20000),
                            @"name":searchController.searchBar.text,
                            @"key":GOOGLE_PLACE_API_KEY
                            };
    AFHTTPSessionManager *manager=[[AFHTTPSessionManager alloc] init];
    [manager GET:GoogleURL parameters:param progress:^(NSProgress * _Nonnull downloadProgress) {

    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
         NSLog(@"%@", responseObject);
        if ([[responseObject objectForKey:@"status"] isEqualToString:@"OK"]) {
            self.resultsArray = [SWGooglePlace getLocationForApp:[responseObject objectForKey:@"results"]];     
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@", error.localizedDescription);
    }];

例如,如果我住在纽约,我输入的城市没有找到结果。只有在纽约市内显示的地方。

1 个答案:

答案 0 :(得分:0)

当你从google places api到附近的地方然后找到纬度,经度,城市,国家时,你必须使用这种CLGeocoder方法

    CLGeocoder *geocode = [CLGeocoder new];

    [_geoCoder geocodeAddressString:yourstring completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {

        NSLog(@"%@",placemarks[0]);

    }];

这里的地址字符串你必须传递api格式的字符串结果,它将为你提供该地点的整个数据,然后你可以从城市或国家的结果中提取特定的数据。

相关问题