【发布时间】:2015-08-03 07:12:46
【问题描述】:
有什么方法可以从placeID 获取GSMAddress。我有兴趣使用从autocompleteQuery 方法获得的placeID 获取地址。
P.S:我有一个 placeID 并想办法在 iOS 中获取对应的 GMSAddress。
我找到了一个帖子 here 但这没有帮助。
谢谢,
【问题讨论】:
标签: ios google-maps
有什么方法可以从placeID 获取GSMAddress。我有兴趣使用从autocompleteQuery 方法获得的placeID 获取地址。
P.S:我有一个 placeID 并想办法在 iOS 中获取对应的 GMSAddress。
我找到了一个帖子 here 但这没有帮助。
谢谢,
【问题讨论】:
标签: ios google-maps
自动完成后,我们进行地点查找,然后将坐标传递给 GMSGeocoder 以检索详细信息,但我仍然缺少 street_name 和 street_number。
CLLocationCoordinate2D addressCoordinates = CLLocationCoordinate2DMake(latitude,longitude);
GMSGeocoder* coder = [[GMSGeocoder alloc] init];
[coder reverseGeocodeCoordinate:addressCoordinates completionHandler:^(GMSReverseGeocodeResponse *results, NSError *error) {
if (error) {
NSLog(@"Error %@", error.description);
} else {
GMSAddress* address = [results firstResult];
NSLog(@"thoroughfare %@",address.thoroughfare);
NSLog(@"locality %@",address.locality);
NSLog(@"subLocality %@",address.subLocality);
NSLog(@"administrativeArea %@",address.administrativeArea);
NSLog(@"postalCode %@",address.postalCode);
NSLog(@"country %@",address.country);
NSLog(@"lines %@",address.lines);
}
}];
我正在考虑切换到 iOS 自己的反向地理编码器。
[CLGeocoder reverseGeocodeLocation:[[CLLocation alloc] initWithLatitude:latitude longitude:longitude] completionHandler:
^(NSArray* placemarks, NSError* error) {
【讨论】:
似乎没有直接的方法可以从GMSPlace placeID 获取GSMAddress。
我想出的一种方法是使用GMSGeocoder().reverseGeocodeCoordinate 方法以及来自GMSPlace 的coordinate 属性。
我遵循的步骤可以总结为:
lookUpPlaceID方法找到coordinates
lookUpPlaceID 获得的coordinates 反向地理编码
代码如下:
placesClient?.lookUpPlaceID(placeID, callback: {
(place, error) -> Void in
// Get place.coordinate
GMSGeocoder().reverseGeocodeCoordinate(place!.coordinate, completionHandler: {
(response, error) -> Void in
for addObj in response.results() {
// Address object
}
})
})
欢迎评论和更好的解决方案。
【讨论】: