【问题标题】:Get GMSAddress from GMSPlace placeID从 GMSPlace placeID 获取 GMSAddress
【发布时间】:2015-08-03 07:12:46
【问题描述】:

有什么方法可以从placeID 获取GSMAddress。我有兴趣使用从autocompleteQuery 方法获得的placeID 获取地址。

P.S:我有一个 placeID 并想办法在 iOS 中获取对应的 GMSAddress

我找到了一个帖子 here 但这没有帮助。

谢谢,

【问题讨论】:

    标签: ios google-maps


    【解决方案1】:

    自动完成后,我们进行地点查找,然后将坐标传递给 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) {
    

    【讨论】:

    • 我想要完全相反的东西。从地址获取 lat long .. GMSGeocoder 怎么可能!
    • 这可以获得街道名称和街道号码。在 swift 4.1 Xcode 9.4.1 中查看我的答案。您甚至可以获得村庄名称的详细信息。 stackoverflow.com/questions/16647996/…
    【解决方案2】:

    似乎没有直接的方法可以从GMSPlace placeID 获取GSMAddress

    我想出的一种方法是使用GMSGeocoder().reverseGeocodeCoordinate 方法以及来自GMSPlacecoordinate 属性。

    我遵循的步骤可以总结为:

    1. 使用lookUpPlaceID方法找到coordinates
    2. 使用从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
                }
            })
        })
    

    欢迎评论和更好的解决方案。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-20
    • 2016-12-24
    • 1970-01-01
    相关资源
    最近更新 更多