我正在使用Google Places API for iOS的自动完成功能,它返回placeID。如何从placeID获取GMSAddress?我目前使用lookupPlaceID获取GMSPlace,然后使用reverseGeocodeCoordinate从GMSPlace中的coordinate获取GMSAddress。但是它请求Google API 3次: AutoComplete,lookupPlaceID,reverseGeocodeCoordinate。
有没有办法直接从PlaceID或GMSPlace获取GMSAddress?
发布于 2015-07-14 23:12:52
发布于 2016-10-06 05:36:39
我可以在一个API调用中从placedID获取地址,代码如下:
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);
}
}];发布于 2015-10-29 16:14:35
现在,下面的代码对于这个版本的SDK (1.10.5)是否安全(足够)?在接下来的6个月内,这一点被打破的概率是多少?
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"]);
}https://stackoverflow.com/questions/31106534
复制相似问题