从邮政编码 Google 地图访问州信息
Accessing State Information from Zip Code Google Maps
当用户输入邮政编码时,我能够从 google 地图 api (https://maps.googleapis.com/maps/api/geocode) 中获取状态。但是,出于某种原因,州信息的位置会根据邮政编码而变化。
我能想到的唯一解决方案是查询两个可能的位置并将它们存储在变量中并检查状态,但这似乎不太实用。
//sometimes it's located in this area (the state short name like CA)
$thestate['results'][0]['address_components'][4]['short_name'];
//other times it's located here
$thestate['results'][0]['address_components'][3]['short_name'];
知道如何每次都能准确选择状态 short_name 吗?他们会移动位置似乎很奇怪,我正在努力准确地把它拉出来。
您需要找到类型为 administrative_area_level_1
的 address_components
条目。
administrative_area_level_1 indicates a first-order civil entity below
the country level. Within the United States, these administrative
levels are states. Not all nations exhibit these administrative
levels. In most cases, administrative_area_level_1 short names will
closely match ISO 3166-2 subdivisions and other widely circulated
lists; however this is not guaranteed as our geocoding results are
based on a variety of signals and location data.
来自here
当用户输入邮政编码时,我能够从 google 地图 api (https://maps.googleapis.com/maps/api/geocode) 中获取状态。但是,出于某种原因,州信息的位置会根据邮政编码而变化。
我能想到的唯一解决方案是查询两个可能的位置并将它们存储在变量中并检查状态,但这似乎不太实用。
//sometimes it's located in this area (the state short name like CA)
$thestate['results'][0]['address_components'][4]['short_name'];
//other times it's located here
$thestate['results'][0]['address_components'][3]['short_name'];
知道如何每次都能准确选择状态 short_name 吗?他们会移动位置似乎很奇怪,我正在努力准确地把它拉出来。
您需要找到类型为 administrative_area_level_1
的 address_components
条目。
administrative_area_level_1 indicates a first-order civil entity below the country level. Within the United States, these administrative levels are states. Not all nations exhibit these administrative levels. In most cases, administrative_area_level_1 short names will closely match ISO 3166-2 subdivisions and other widely circulated lists; however this is not guaranteed as our geocoding results are based on a variety of signals and location data.
来自here