iOS 開発者ガイド for SDK

ジオ コーディングおよび Reverse ジオ コーディング

SDK for iOS のジオ コーディングおよびリバースジオ コーディング API を使用 すると、アプリケーション開発者はNMAPlaceLocation情報を要求するための検索機能を提供できます。 ジオ コーディング API NMAGeoCoordinatesNMAGeoCoordinatesNMAAddressは、への自由形式のテキストクエリを解決します。逆のジオ コーディング API は、からなどの地理的データに解決します。

NMAAddress 住所のテキスト情報を提供します。住所には、番地、番地、市区町村、国、地域、 その他。 住所や地図上のポイントに関するすべての情報が含まれています。 NMAPlaceLocation このクラスは、追加の属性を取得できるマップ上の領域を表します。 これらの追加属性には NMAAddress、一意の識別子、ラベル、場所、アクセス場所、 NMAGeoBoundingBox 場所を指定します。

GitHub でのジオ コーディングおよび Reverse ジオ コーディングの例

この機能を示す例について は、 https://github.com/heremaps/ (Obj-C) および https://github.com/heremaps/ (Swift) を参照してください。

NMAGeocoder インターフェイス

NMAGeocoder インターフェイスは、位置検索要求のインスタンス化に使用されるファクトリクラスを表します。 リクエストには NMAGeocodeRequest 、との 2 種類があります NMAReverseGeocodeRequest

NMAGeocodeRequest インターフェイス

NMAGeocodeRequest インターフェイスは拡張を表し NMARequestます。 は NMAGeocodeRequest 、検索領域とフリーテキストのクエリー文字列を組み合わせて使用して作成できます。 これは「ワンボックス」リクエストと呼ばれます。 NMAPlaceLocation 指定した検索範囲とテキストクエリに基づいて結果が返されます。 NMAGeoBoundingBox または場所に検索範囲を指定することで、検索範囲を指定できます。

ワンボックスリクエストの作成に使用されるメソッドを次に示します。

NMAGeocodeRequest* request = [[NMAGeocoder sharedGeocoder] createGeocodeRequestWithQuery:string
            searchArea:geoBoundingBox
            locationContext:geoCoordinates];
NMAGeocodeRequest* request = [[NMAGeocoder sharedGeocoder] createGeocodeRequestWithQuery:string
            searchRadius:radius
            locationContext:geoCoordinates];

上記のメソッドは NMAGeocodeRequest 、オブジェクトを返します。 リクエストを実行するには startWithListener: 、そのメソッドを呼び出します。 このメソッドのパラメーターは、リクエストの結果を受け取るオブジェクトです。このオブジェクトは NMAResultListener 、プロトコルを実装する必要があります。 リクエストが呼び出されると cancel 、のメソッドを使用してキャンセルでき NMARequestBOOL ます。メソッドは、結果が正常にキャンセルされたかどうかを示す値を返します。 NMAGeocodeRequest が成功すると NMAGeocodeResult 、オブジェクトのリストがリスナーに返されます。

を使用する方法を次のコード例に示し NMAGeocodeRequestます。


// Implementation of NMAResultListener
@interface NMAGeocodeTest : NSObject<NMAResultListener> {
}
@end
@implementation NMAGeocodeTest

// NMAResultListener protocol callback implementation
- (void)request:(NMARequest*)request
    didCompleteWithData:(id)data
    error:(NSError*)error
{
  if ( ( [request isKindOfClass:[NMAGeocodeRequest class]]) &&
    ( error.code == NMARequestErrorNone ) )
  {
    // Process result NSArray of NMAGeocodeResult objects
    [self processResult:(NSMutableArray *)data];
  }
  else
  {
    // Handle error
    ...
  }
}

- (void) startSearch
{
  NMAGeoCoordinates *topLeft =
    [[NMAGeoCoordinates alloc]
      initWithLatitude:52.537413 longitude:13.365641];
  NMAGeoCoordinates *bottomRight =
    [[NMAGeoCoordinates alloc]
      initWithLatitude:52.522428 longitude:13.39345];
  NMAGeoBoundingBox *boundingBox =
    [NMAGeoBoundingBox
      geoBoundingBoxWithTopLeft:topLeft bottomRight:bottomRight];

  NMAGeocodeRequest* request = [[NMAGeocoder sharedGeocoder]
  createGeocodeRequestWithQuery:@"100 INVALIDENSTRASSE"
            searchArea:boundingBox
            locationContext:nil];

  // limit the number of results to 10
  request.collectionSize = 10;

  NSError* error = [request startWithListener:self];
  if (error.code != NMARequestErrorNone)
  {
    // Handle request error
    ...
  }
}
@end

NMAReverseGeocodeRequest インターフェイス

NMAReverseGeocodeRequest インターフェイスは NMARequestNMAPlaceLocation 、データの取得に使用される拡張を表します。 リクエストは NMAGeoCoordinates 、次のようにを使用して作成されます。

NMAGeocodeRequest* request = [[NMAGeocoder sharedGeocoder]
  createReverseGeocodeRequestWithGeoCoordinates:geoCoordinates];

上記のメソッドは NMAReverseGeocodeRequest 、オブジェクトを返します。 リバースジオコードリクエストは、通常のジオコードリクエストと同じ方法で使用されますが ( 前のセクションで説明 ) NMAReverseGeocodeResult 、結果はオブジェクトの配列として返されます。

次の例は、を作成して使用する方法を示し NMAReverseGeocodeRequestています。


// Implementation of NMAResultListener
@interface NMAReverseGeocodeTest : NSObject<NMAResultListener> {
}
@end
@implementation NMAReverseGeocodeTest

// NMAResultListener protocol callback implementation
- (void)request:(NMARequest*)request
  didCompleteWithData:(id)data
  error:(NSError*)error
{
  if ( ( [request isKindOfClass:[NMAReverseGeocodeRequest class]]) &&
    ( error.code == NMARequestErrorNone ) )
  {
    // Process result NSArray of NMAReverseGeocodeResult objects
    [self processResult:(NSMutableArray *)data];
  }
  else
  {
    // Handle error
    ...
  }
}

- (void) startSearch
{
  // Instantiate an Address object
  NMAGeoCoordinates* vancouver = [[NMAGeoCoordinates alloc] initWithLatitude:49.2849 longitude:-123.1252];

  NMAReverseGeocodeRequest* request = [[NMAGeocoder sharedGeocoder] createReverseGeocodeRequestWithGeoCoordinates:vancouver];

  NSError* error = [request startWithListener:self];
  if (error.code != NMARequestErrorNone)
  {
    // Handle request error
    ...
  }
}

@end

既定では、上記のリバースジオコードリクエストは、最も近い番地を検索します。 または、次のいずれかのモードでリバースジオ コーディングリクエストを作成することもできNMAReverseGeocodeModeます () 。

  • NMAReverseGeocodeModeRetrieveAddresses - 最寄りの番地を検索 ( 上記と同じ )
  • NMAReverseGeocodeModeRetrieveAreas - リクエストで指定された位置の管理エリア情報を取得します
  • NMAReverseGeocodeModeRetrieveLandmarks - リクエストに応じて、公園や湖などのランドマークを検索できます
  • NMAReverseGeocodeModeRetrieveAll - 通り、行政エリア、ランドマークを検索します。 このモードでは、 1 回の呼び出しで、前の 3 つのモードの結果が集約されます
  • NMAReverseGeocodeModeTrackPosition - 位置と方位に基づいて、番地と番地の情報を取得します

このタイプのリクエストの使用例については、次のトピックを参照してください。 bearing パラメータは、を使用する場合にのみ使用 NMAReverseGeocodeModeTrackPositionされます。

NMAReverseGeocodeRequest* request = [[NMAGeocoder sharedGeocoder]
  createReverseGeocodeRequestWithGeoCoordinates:geoCoordinates
  mode:NMAReverseGeocodeModeRetrieveLandmarks
  bearing:0];

[request startWithBlock:^(NMARequest *request, id data, NSError *error) {
    if(!error) {
      NSArray *results = (NSArray*)data;
      NMAReverseGeocodeResult *result = nil;
      NSMutableString *address = [NSMutableString new];

      for (NSUInteger i = 0; i < results.count; i ++) {
        result = [results objectAtIndex:i];

        [address appendFormat:@"%ld.\n", i + 1];

        if (result.distance > 0) {
          [address appendFormat:@"distance:%.2f\n", result.distance];
        }
        if (result.location.address.houseNumber) {
          [address appendFormat:@"houseNo:%@\n", result.location.address.houseNumber];
        }
        if (result.location.address.street) {
          [address appendFormat:@"street:%@\n", result.location.address.street];
        }
        if (result.location.address.city) {
          [address appendFormat:@"city:%@\n", result.location.address.city];
        }
        if (result.location.address.state) {
          [address appendFormat:@"state:%@\n", result.location.address.state];
        }
        if (result.location.address.postalCode) {
          [address appendFormat:@"postalCode:%@\n", result.location.address.postalCode];
        }
        if (result.location.address.countryName) {
          [address appendFormat:@"country:%@\n", result.location.address.countryName];
        }
        if (result.location.timeZone) {
          [address appendFormat:@"timeZone:%@\n\n", result.location.timeZone.name];
        }
      }
    }
   }];

オフラインジオ コーディング

SDK for iOS で開発されたアプリケーションは、オフラインのジオ コーディングを実行できます。これにより、アクティブなデータ接続なしでジオコードおよびリバースジオコードリクエストを実行できます。 これは、マップおよびデータベースの情報が以前にダウンロードされている限り、アクティブなデータ接続が利用できない場合に自動的に行われます。 データ接続が利用可能になると 、 HERE SDK は まずオンラインでリクエストの実行を試みます。

このセクションで紹介およびデモンストレーションされた API の詳細について は、 API リファレンス のドキュメントを参照してください。