2016-07-15 17 views
2

Google Maps APIを使用して郵便番号の座標を取得したいと考えています。郵便番号検索のためのGoogle Maps API地域パラメータ

私はこの文書を使用しています:私は今、郵便番号1200(スイスジュネーブ)を検索したい場合は、私はこのURLを使用https://developers.google.com/maps/documentation/geocoding/intro?csw=1

:私は異なる結果の多くを取得
https://maps.google.com/maps/api/geocode/json?region=ch&components=postal_code:1200

が、スイスには誰もいません(これの結果は問題の終わりです)。他のカウンターで結果を得るため、リージョンパラメーターが全く機能しないようです。

私が1201(Genèveも)を検索するとうまくいきます。

理由は何ですか?私はむしろ間違った結果(その他の国における結果)

{ 
    "results" : [ 
     { 
     "address_components" : [ 
      { 
       "long_name" : "1200", 
       "short_name" : "1200", 
       "types" : [ "postal_code" ] 
      }, 
      { 
       "long_name" : "Region Brüssel-Hauptstadt", 
       "short_name" : "Region Brüssel-Hauptstadt", 
       "types" : [ "administrative_area_level_1", "political" ] 
      }, 
      { 
       "long_name" : "Belgien", 
       "short_name" : "BE", 
       "types" : [ "country", "political" ] 
      } 
     ], 
     "formatted_address" : "1200, Belgien", 
     "geometry" : { 
      "bounds" : { 
       "northeast" : { 
        "lat" : 50.86307189999999, 
        "lng" : 4.4629024 
       }, 
       "southwest" : { 
        "lat" : 50.8337598, 
        "lng" : 4.3999935 
       } 
      }, 
      "location" : { 
       "lat" : 50.850308, 
       "lng" : 4.4278228 
      }, 
      "location_type" : "APPROXIMATE", 
      "viewport" : { 
       "northeast" : { 
        "lat" : 50.86307189999999, 
        "lng" : 4.4629024 
       }, 
       "southwest" : { 
        "lat" : 50.8337598, 
        "lng" : 4.3999935 
       } 
      } 
     }, 
     "place_id" : "ChIJNa8iqqHcw0cRG4NyYbv66KY", 
     "types" : [ "postal_code" ] 
     }, 
     { 
     "address_components" : [ 
      { 
       "long_name" : "1200", 
       "short_name" : "1200", 
       "types" : [ "postal_code" ] 
      }, 
      { 
       "long_name" : "Wien", 
       "short_name" : "Wien", 
       "types" : [ "locality", "political" ] 
      }, 
      { 
       "long_name" : "Wien", 
       "short_name" : "Wien", 
       "types" : [ "postal_town" ] 
      }, 
      { 
       "long_name" : "Wien", 
       "short_name" : "Wien", 
       "types" : [ "administrative_area_level_1", "political" ] 
      }, 
      { 
       "long_name" : "Österreich", 
       "short_name" : "AT", 
       "types" : [ "country", "political" ] 
      } 
     ], 
     "formatted_address" : "1200 Wien, Österreich", 
     "geometry" : { 
      "bounds" : { 
       "northeast" : { 
        "lat" : 48.2646423, 
        "lng" : 16.4007913 
       }, 
       "southwest" : { 
        "lat" : 48.2252299, 
        "lng" : 16.3618448 
       } 
      }, 
      "location" : { 
       "lat" : 48.235668, 
       "lng" : 16.373098 
      }, 
      "location_type" : "APPROXIMATE", 
      "viewport" : { 
       "northeast" : { 
        "lat" : 48.2646423, 
        "lng" : 16.4007913 
       }, 
       "southwest" : { 
        "lat" : 48.2252299, 
        "lng" : 16.3618448 
       } 
      } 
     }, 
     "place_id" : "ChIJs0PDoUQGbUcRI9VvmpZbVzQ", 
     "types" : [ "postal_code" ] 
     }, 
     { 
     "address_components" : [ 
      { 
       "long_name" : "1200", 
       "short_name" : "1200", 
       "types" : [ "postal_code", "postal_code_prefix" ] 
      }, 
      { 
       "long_name" : "Lissabon", 
       "short_name" : "Lissabon", 
       "types" : [ "locality", "political" ] 
      }, 
      { 
       "long_name" : "Lissabon", 
       "short_name" : "Lissabon", 
       "types" : [ "administrative_area_level_1", "political" ] 
      }, 
      { 
       "long_name" : "Portugal", 
       "short_name" : "PT", 
       "types" : [ "country", "political" ] 
      } 
     ], 
     "formatted_address" : "1200 Lissabon, Portugal", 
     "geometry" : { 
      "bounds" : { 
       "northeast" : { 
        "lat" : 38.7177413, 
        "lng" : -9.1387655 
       }, 
       "southwest" : { 
        "lat" : 38.7006072, 
        "lng" : -9.168078299999999 
       } 
      }, 
      "location" : { 
       "lat" : 38.7096083, 
       "lng" : -9.1539178 
      }, 
      "location_type" : "APPROXIMATE", 
      "viewport" : { 
       "northeast" : { 
        "lat" : 38.7177413, 
        "lng" : -9.1387655 
       }, 
       "southwest" : { 
        "lat" : 38.7006072, 
        "lng" : -9.168078299999999 
       } 
      } 
     }, 
     "place_id" : "ChIJT3JAUYI0GQ0R4Nc7DsHrABw", 
     "types" : [ "postal_code", "postal_code_prefix" ] 
     }, 
     { 
     "address_components" : [ 
      { 
       "long_name" : "1200", 
       "short_name" : "1200", 
       "types" : [ "postal_code" ] 
      }, 
      { 
       "long_name" : "Mbombela", 
       "short_name" : "Mbombela", 
       "types" : [ "locality", "political" ] 
      }, 
      { 
       "long_name" : "Mbombela", 
       "short_name" : "Mbombela", 
       "types" : [ "administrative_area_level_3", "political" ] 
      }, 
      { 
       "long_name" : "Ehlanzeni", 
       "short_name" : "Ehlanzeni", 
       "types" : [ "administrative_area_level_2", "political" ] 
      }, 
      { 
       "long_name" : "Mpumalanga", 
       "short_name" : "MP", 
       "types" : [ "administrative_area_level_1", "political" ] 
      }, 
      { 
       "long_name" : "Südafrika", 
       "short_name" : "ZA", 
       "types" : [ "country", "political" ] 
      } 
     ], 
     "formatted_address" : "Mbombela, 1200, Südafrika", 
     "geometry" : { 
      "bounds" : { 
       "northeast" : { 
        "lat" : -25.434559, 
        "lng" : 31.035606 
       }, 
       "southwest" : { 
        "lat" : -25.5273621, 
        "lng" : 30.9615131 
       } 
      }, 
      "location" : { 
       "lat" : -25.4922163, 
       "lng" : 31.0048384 
      }, 
      "location_type" : "APPROXIMATE", 
      "viewport" : { 
       "northeast" : { 
        "lat" : -25.434559, 
        "lng" : 31.035606 
       }, 
       "southwest" : { 
        "lat" : -25.5273621, 
        "lng" : 30.9615131 
       } 
      } 
     }, 
     "place_id" : "ChIJC-Upoo1J6B4RbhfORqGdY2s", 
     "types" : [ "postal_code" ] 
     }, 
     { 
     "address_components" : [ 
      { 
       "long_name" : "1200", 
       "short_name" : "1200", 
       "types" : [ "postal_code" ] 
      }, 
      { 
       "long_name" : "København K", 
       "short_name" : "København K", 
       "types" : [ "political", "sublocality", "sublocality_level_1" ] 
      }, 
      { 
       "long_name" : "København", 
       "short_name" : "København", 
       "types" : [ "locality", "political" ] 
      }, 
      { 
       "long_name" : "Dänemark", 
       "short_name" : "DK", 
       "types" : [ "country", "political" ] 
      } 
     ], 
     "formatted_address" : "1200 København K, Dänemark", 
     "geometry" : { 
      "bounds" : { 
       "northeast" : { 
        "lat" : 55.6788537, 
        "lng" : 12.581048 
       }, 
       "southwest" : { 
        "lat" : 55.6774083, 
        "lng" : 12.5790574 
       } 
      }, 
      "location" : { 
       "lat" : 55.6780957, 
       "lng" : 12.5799054 
      }, 
      "location_type" : "APPROXIMATE", 
      "viewport" : { 
       "northeast" : { 
        "lat" : 55.6794799802915, 
        "lng" : 12.5814016802915 
       }, 
       "southwest" : { 
        "lat" : 55.6767820197085, 
        "lng" : 12.5787037197085 
       } 
      } 
     }, 
     "place_id" : "ChIJuYvG1hZTUkYREL3-tlYomQk", 
     "types" : [ "postal_code" ] 
     } 
    ], 
    "status" : "OK" 
} 
+0

これらのドキュメントによれば、地域コード_ "はジオコーダーの結果にのみ影響を与えますが、完全に制限されるわけではありません" _ – duncan

答えて

2

ダンカンが言ったように、region codeは影響のみではなく、完全に制限されます、ジオコーダの結果、次にていない任意の結果を得るでしょう。詳細については、region biasingをご確認ください。

特定の結果を国で使用する場合は、地域の代わりにのcomponent = countryを使用します。

スイス国で郵便番号:1200をリクエストしようとしました。そして私はゼロの結果を得ます。そのため、使用しているリクエストが有効であることを確認してください。

https://maps.google.com/maps/api/geocode/json?components=postal_code:1200|country:CH 

そして、私はPOSTAL_CODEしようとした場合:1201を、私はあなたが望む特定の結果を得ます。

https://maps.google.com/maps/api/geocode/json?components=postal_code:1201|country:CH 

あなたはPOSTAL_CODEことが確実な場合:1200は多分そのPOSTAL_CODEは、Googleマップで、スイス・ジュネーブのための郵便番号とはみなされません、スイスで有効な郵便番号です。

私が答えたこの関連性を確認してみてください。SO question

+0

コンポーネントを使用する国はいいですし、必要なものです。 ** postal_code:1200 **はちょっと変わっています – nbar

関連する問題