24

GMSReverseGeocodeResponse含む

- (GMSReverseGeocodeResult *)firstResult;

その定義は次のようなものです:

@interface GMSReverseGeocodeResult : NSObject<NSCopying>

/** Returns the first line of the address. */
- (NSString *)addressLine1;

/** Returns the second line of the address. */
- (NSString *)addressLine2;

@end

これら2つの文字列から国、ISO国コード、州(administrative_area_1または対応するもの)を取得する方法はありますか(すべての国すべての住所に有効)?

注:このコードを実行しようとしました

[[GMSGeocoder geocoder] reverseGeocodeCoordinate:CLLocationCoordinate2DMake(40.4375, -3.6818) completionHandler:^(GMSReverseGeocodeResponse *resp, NSError *error)
 {
    NSLog( @"Error is %@", error) ;
    NSLog( @"%@" , resp.firstResult.addressLine1 ) ;
    NSLog( @"%@" , resp.firstResult.addressLine2 ) ;
 } ] ;

しかし、何らかの理由でハンドラーが呼び出されませんでした。アプリキーを追加し、iOS バンドル ID もアプリキーに追加しました。コンソールにエラーは出力されません。これは、行の内容を認識していないことを意味します。

4

4 に答える 4

39

最も簡単な方法は、Google Maps SDK for iOS (2014 年 2 月リリース)のバージョン 1.7 にアップグレードすることです。リリースノート から:

GMSGeocoderGMSAddressは、非推奨の経由で構造化アドレスを提供するようになりGMSReverseGeocodeResultました。

GMSAddressClass Referenceから、次のプロパティを見つけることができます。

coordinate
場所、またはkLocationCoordinate2DInvalid不明な場合。

thoroughfare
番地と名前。

locality
地方または都市。

subLocality
地域、地区、または公園の下位区分。

administrativeArea
地域/州/行政区域。

postalCode
郵便番号。

country
国名。

lines
NSString住所の書式設定された行を含む 配列。

ただし、ISO 国コードはありません。
また、一部のプロパティは を返す場合があることに注意してくださいnil

完全な例を次に示します。

[[GMSGeocoder geocoder] reverseGeocodeCoordinate:CLLocationCoordinate2DMake(40.4375, -3.6818) completionHandler:^(GMSReverseGeocodeResponse* response, NSError* error) {
    NSLog(@"reverse geocoding results:");
    for(GMSAddress* addressObj in [response results])
    {
        NSLog(@"coordinate.latitude=%f", addressObj.coordinate.latitude);
        NSLog(@"coordinate.longitude=%f", addressObj.coordinate.longitude);
        NSLog(@"thoroughfare=%@", addressObj.thoroughfare);
        NSLog(@"locality=%@", addressObj.locality);
        NSLog(@"subLocality=%@", addressObj.subLocality);
        NSLog(@"administrativeArea=%@", addressObj.administrativeArea);
        NSLog(@"postalCode=%@", addressObj.postalCode);
        NSLog(@"country=%@", addressObj.country);
        NSLog(@"lines=%@", addressObj.lines);
    }
}];

およびその出力:

coordinate.latitude=40.437500
coordinate.longitude=-3.681800
thoroughfare=(null)
locality=(null)
subLocality=(null)
administrativeArea=Community of Madrid
postalCode=(null)
country=Spain
lines=(
    "",
    "Community of Madrid, Spain"
)

または、 Google Geocoding APIリバース ジオコーディングを使用することを検討することもできます()。

于 2014-02-17T02:05:40.220 に答える