不同状态的地理编码 returns JSON 没有界限
Geocode for different state returns JSON without bounds
当我从 http://maps.googleapis.com/maps/api/geocode/json?address=Alabama
得到 JSON 时,它返回我的边界,如你所见:
{
"results" : [
{
"address_components" : [
{
"long_name" : "Alabama",
"short_name" : "AL",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Alabama, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 35.008028,
"lng" : -84.888246
},
"southwest" : {
"lat" : 30.144425,
"lng" : -88.4732269
}
},
"location" : {
"lat" : 32.3182314,
"lng" : -86.902298
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 35.008028,
"lng" : -84.888246
},
"southwest" : {
"lat" : 30.144425,
"lng" : -88.4732269
}
}
},
"place_id" : "ChIJdf5LHzR_hogR6czIUzU0VV4",
"types" : [ "administrative_area_level_1", "political" ]
}
],
"status" : "OK"
}
但是当我输入阿拉斯加而不是阿拉巴马时 http://maps.googleapis.com/maps/api/geocode/json?address=Alaska
{
"results" : [
{
"address_components" : [
{
"long_name" : "700",
"short_name" : "700",
"types" : [ "street_number" ]
},
{
"long_name" : "East 46th Avenue",
"short_name" : "E 46th Ave",
"types" : [ "route" ]
},
{
"long_name" : "Midtown",
"short_name" : "Midtown",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Anchorage",
"short_name" : "Anchorage",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Anchorage",
"short_name" : "Anchorage",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Alaska",
"short_name" : "AK",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "99503",
"short_name" : "99503",
"types" : [ "postal_code" ]
},
{
"long_name" : "7402",
"short_name" : "7402",
"types" : [ "postal_code_suffix" ]
}
],
"formatted_address" : "700 E 46th Ave, Anchorage, AK 99503, USA",
"geometry" : {
"location" : {
"lat" : 61.1789309,
"lng" : -149.870464
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 61.1802798802915,
"lng" : -149.8691150197085
},
"southwest" : {
"lat" : 61.17758191970849,
"lng" : -149.8718129802915
}
}
},
"place_id" : "ChIJ1QZWYr2XyFYR1-572SNQDyI",
"types" : [ "car_wash", "establishment", "finance", "point_of_interest" ]
}
],
"status" : "OK"
}
JSON 中没有 "bounds"
,为什么,我需要边界以便我可以搜索美国各州的特定位置。
有什么区别,这发生在其他一些州。
我尝试使用视口而不是边界,它再次适用于阿拉巴马州,但在阿拉斯加,它指向安克雷奇的中心。
实际上,有一个解决方法。您需要在请求中添加 'components' 参数和 select 'country' 进行过滤。
这是一个示例 link http://maps.googleapis.com/maps/api/geocode/json?address=Alaska&components=country:US
注意:可选择返回边界
bounds (optionally returned) stores the bounding box which can fully contain the returned result.
希望对您的问题有所帮助。
当我从 http://maps.googleapis.com/maps/api/geocode/json?address=Alabama
得到 JSON 时,它返回我的边界,如你所见:
{
"results" : [
{
"address_components" : [
{
"long_name" : "Alabama",
"short_name" : "AL",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Alabama, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 35.008028,
"lng" : -84.888246
},
"southwest" : {
"lat" : 30.144425,
"lng" : -88.4732269
}
},
"location" : {
"lat" : 32.3182314,
"lng" : -86.902298
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 35.008028,
"lng" : -84.888246
},
"southwest" : {
"lat" : 30.144425,
"lng" : -88.4732269
}
}
},
"place_id" : "ChIJdf5LHzR_hogR6czIUzU0VV4",
"types" : [ "administrative_area_level_1", "political" ]
}
],
"status" : "OK"
}
但是当我输入阿拉斯加而不是阿拉巴马时 http://maps.googleapis.com/maps/api/geocode/json?address=Alaska
{
"results" : [
{
"address_components" : [
{
"long_name" : "700",
"short_name" : "700",
"types" : [ "street_number" ]
},
{
"long_name" : "East 46th Avenue",
"short_name" : "E 46th Ave",
"types" : [ "route" ]
},
{
"long_name" : "Midtown",
"short_name" : "Midtown",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Anchorage",
"short_name" : "Anchorage",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Anchorage",
"short_name" : "Anchorage",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Alaska",
"short_name" : "AK",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "99503",
"short_name" : "99503",
"types" : [ "postal_code" ]
},
{
"long_name" : "7402",
"short_name" : "7402",
"types" : [ "postal_code_suffix" ]
}
],
"formatted_address" : "700 E 46th Ave, Anchorage, AK 99503, USA",
"geometry" : {
"location" : {
"lat" : 61.1789309,
"lng" : -149.870464
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 61.1802798802915,
"lng" : -149.8691150197085
},
"southwest" : {
"lat" : 61.17758191970849,
"lng" : -149.8718129802915
}
}
},
"place_id" : "ChIJ1QZWYr2XyFYR1-572SNQDyI",
"types" : [ "car_wash", "establishment", "finance", "point_of_interest" ]
}
],
"status" : "OK"
}
JSON 中没有 "bounds"
,为什么,我需要边界以便我可以搜索美国各州的特定位置。
有什么区别,这发生在其他一些州。
我尝试使用视口而不是边界,它再次适用于阿拉巴马州,但在阿拉斯加,它指向安克雷奇的中心。
实际上,有一个解决方法。您需要在请求中添加 'components' 参数和 select 'country' 进行过滤。
这是一个示例 link http://maps.googleapis.com/maps/api/geocode/json?address=Alaska&components=country:US
注意:可选择返回边界
bounds (optionally returned) stores the bounding box which can fully contain the returned result.
希望对您的问题有所帮助。