I am using Autocomplete of Google Places API for iOS, and it returns placeID. How can I get GMSAddress from the placeID? I currently use lookupPlaceID to get GMSPlace, and then use reverseGeocodeCoordinate to get GMSAddress from coordinate in GMSPlace. But it request Google API 3 times: AutoComplete, lookupPlaceID, reverseGeocodeCoordinate.
Is there any way to get GMSAddress from PlaceID or GMSPlace directly?
This is a bug with 1.1.0 of the Google Maps SDK for iOS. See here.
As the documentation states here, the address
property should expose a GMSAddress
on GMSPlace
instances.
I've just switched to using the REST API. It's not too bad to write a quick wrapper for the API and ditch the Google SDK completely. If you are using Alamofire ping me and I may be able to share what I've written.
I could get the address from placedID 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);
}
}];
Now for the time being, is the code below safe (enough) for this version of the SDK (1.10.5)? What is the probability 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"]);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With