Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Google マップのジオコーディング要求を実行すると、次のような応答を受け取ります。

{
   "results" :
   [
      {
         "formatted_address" :"1600 Amphitheatre Parkway, Mountain View, CA 94043, USA",
         "geometry" :
         {
            "location" :
            {
               "lat" :37.4224764,
               "lng" :-122.0842499
            }
        }
    ]
}

ここで注目するのは、latlong の値です。これは、 results (element 1) >> geometry >> location 経由でアクセスできます。

Define_Com Class(#XPRIM_HttpRequest) Name(#Req)
Define_Com Class(#XPRIM_RandomAccessJsonReader) Name(#Reader)
...
#Req.DoGet Url('https://maps.googleapis.com/maps/api/geocode/json?...')

 * 要求が正しく実行されたか確認
If (#Req.Response.IsSuccessHttpStatusCode)
     * 応答のJSON リーダー・ソースを HTTP 要求から設定
    #Reader.SetSourceHttpResponse HttpResponse(#Req.Response)
     *  ('lat' と 'lng' 値が含まれている) 'location' オブジェクトにナビゲート
     * ナビゲーション・パスを指定して、'location' エレメントへナビゲート
     * パスの名前とインデックスはスラッシュで区切る
    #Reader.BeginObjectWithPath Path('results/1/geometry/location')
     * 緯度と経度の値を取得
    #Latitude := #Reader.ReadNumberWithName('lat')
    #Longitude := #Reader.ReadNumberWithName('lng')
     * "BeginObject" を "EndObject" で終了
    #Reader.EndObject
Endif

次は: 無効な応答を確認