从GMSPlace获取城市名称

时间:2016-10-25 17:44:41

标签: google-maps google-maps-sdk-ios

我正试图通过此方法在GMSPlace上获取自动完成的城市名称
- (void)viewController:(GMSAutocompleteViewController *)viewController didAutocompleteWithPlace:(GMSPlace *)place { }

2 个答案:

答案 0 :(得分:1)

首先GMSPlace没有城市房产,但我认为可能使用workAround我们可以解决您的问题,也许使用带有coordinate属性的地理编码器

- (void)viewController:(GMSAutocompleteViewController *)viewController
didAutocompleteWithPlace:(GMSPlace *)place 
{
      [[GMSGeocoder geocoder] reverseGeocodeCoordinate:[place coordinate] completionHandler:
     ^(GMSReverseGeocodeResponse *response, NSError *error){
         if(error)
         {
             failed(error);
             return;
         }

         NSString * city = [response.firstResult locality];               
     }];
}

我希望这能帮到你,最好的问候

答案 1 :(得分:-1)

-(BOOL)viewController:(GMSAutocompleteViewController *)viewController didSelectPrediction:(GMSAutocompletePrediction *)prediction{
    return  YES;
}

-(void)viewController:(GMSAutocompleteViewController *)viewController didAutocompleteWithPlace:(GMSPlace *)place{


    addressStr = place.formattedAddress;

    CGFloat lat = place.coordinate.latitude;
    CGFloat longitudeVal = place.coordinate.longitude;

    latStr = [NSString stringWithFormat:@"%f",lat];
    lngStr = [NSString stringWithFormat:@"%f",longitudeVal];

    [self dismissViewControllerAnimated:YES completion:nil];
    [_rentParkingTableView reloadData];

}

-(void)viewController:(GMSAutocompleteViewController *)viewController didFailAutocompleteWithError:(NSError *)error{

}

-(void)wasCancelled:(GMSAutocompleteViewController *)viewController{
    [self dismissViewControllerAnimated:YES completion:nil];
}