How to get GMSAddress from PlaceID or GMSPlace

I am using the Google Places Autocomplete API for iOS and it returns placeID. How can I get a GMSAddress from a place id? I am currently using lookupPlaceID to get the GMSPlace, and then use reverseGeocodeCoordinate to get the GMSAddress from the coordinates in the GMSPlace. But he requests the Google API 3 times: autocomplete, lookupPlaceID, reverseGeocodeCoordinate.

Is there a way to get GMSAddress from PlaceID or GMSPlace directly?

+6
source share
3 answers

This is a bug with the 1.1.0 SDK for Google Maps for iOS. See here .

As stated in the documentation here , the address property should expose instances of GMSAddress on GMSPlace .

I just switched to using the REST API. It's not too bad to write a short API wrapper and completely remove the Google SDK. If you use Alamofire ping me, and I can share what I wrote.

+5
source

I could get the address from putID in one API call, here is the code:

 GMSPlacesClient *placesClient = [[GMSPlacesClient alloc] init]; [placesClient lookUpPlaceID:result.placeID callback:^(GMSPlace *place, NSError *error) { if (error != nil) { NSLog(@"Place Details error %@", [error localizedDescription]); return; } if (place != nil) { NSString *locality = @""; for (GMSAddressComponent *add in place.addressComponents) { //locality NSLog(@"%@",add.type); NSLog(@"%@",add.name); //type will be street_name, locality, admin_area, country, //name will hold the corresponding value } } else { NSLog(@"No place details for %@", result.placeID); } }]; 
+3
source

At the moment, is the code below safe (sufficient) for this version of the SDK (1.10.5)? What is the likelihood that this will break in the next 6 months?

 NSArray* dic = [place valueForKey:@"addressComponents"]; for (int i=0;i<[dic count];i++) { if ([[[dic objectAtIndex:i] valueForKey:@"type"] isEqualToString:@"street_number"]) { NSLog(@"street_number: %@",[[dic objectAtIndex:i] valueForKey:@"name"]); } 
+1
source

Source: https://habr.com/ru/post/989904/


All Articles