【发布时间】:2015-02-21 12:03:42
【问题描述】:
如何从google-api返回的json获取地址
这是我的请求 url,我没有在我提供的示例 url 中包含 api
这里是示例网址:
https://maps.googleapis.com/maps/api/geocode/json?latlng=55.567,56.786&key=xyz
如何获取 google json 返回的格式化地址?
这是我的 json
{
"results" : [
{
"address_components" : [
{
"long_name" : "452377",
"short_name" : "452377",
"types" : [ "postal_code" ]
},
{
"long_name" : "Republic of Bashkortostan",
"short_name" : "Republic of Bashkortostan",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Russia",
"short_name" : "RU",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Republic of Bashkortostan, Russia, 452377",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 55.655173,
"lng" : 57.0644709
},
"southwest" : {
"lat" : 55.36128,
"lng" : 56.6011809
}
},
"location" : {
"lat" : 55.50385139999999,
"lng" : 56.900913
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 55.655173,
"lng" : 57.0644709
},
"southwest" : {
"lat" : 55.36128,
"lng" : 56.6011809
}
}
},
"place_id" : "ChIJ904w9b1u3EMRc1XU4GlYSGs",
"types" : [ "postal_code" ]
},
{
"address_components" : [
{
"long_name" : "Karaidelsky District",
"short_name" : "Karaidelsky District",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Republic of Bashkortostan",
"short_name" : "Republic of Bashkortostan",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Russia",
"short_name" : "RU",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Karaidelsky District, Republic of Bashkortostan, Russia",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 56.076375,
"lng" : 57.7045048
},
"southwest" : {
"lat" : 55.463071,
"lng" : 56.230281
}
},
"location" : {
"lat" : 55.73996589999999,
"lng" : 56.8548154
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 56.076375,
"lng" : 57.7045048
},
"southwest" : {
"lat" : 55.463071,
"lng" : 56.230281
}
}
},
"place_id" : "ChIJCQ7oNrlx3EMRbyb2O6_k5OY",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"address_components" : [
{
"long_name" : "Republic of Bashkortostan",
"short_name" : "Republic of Bashkortostan",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Russia",
"short_name" : "RU",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Republic of Bashkortostan, Russia",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 56.53352,
"lng" : 60.00295010000001
},
"southwest" : {
"lat" : 51.57122589999999,
"lng" : 53.1579969
}
},
"location" : {
"lat" : 54.2312172,
"lng" : 56.1645257
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 56.53352,
"lng" : 60.00295010000001
},
"southwest" : {
"lat" : 51.57122589999999,
"lng" : 53.1579969
}
}
},
"place_id" : "ChIJ_UeUVQW02UMRNFQ0VFqKPHA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"address_components" : [
{
"long_name" : "Russia",
"short_name" : "RU",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Russia",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 81.8581221,
"lng" : -169.045286
},
"southwest" : {
"lat" : 41.185353,
"lng" : 19.6403534
}
},
"location" : {
"lat" : 61.52401,
"lng" : 105.318756
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 70,
"lng" : 179
},
"southwest" : {
"lat" : 40,
"lng" : 27
}
}
},
"place_id" : "ChIJ-yRniZpWPEURE_YRZvj9CRQ",
"types" : [ "country", "political" ]
}
],
"status" : "OK"
}
【问题讨论】:
-
你能把你从url得到的json贴出来吗?
-
results[0].formatted_address -
但是如何打印呢?
-
如果你使用核心php代码,你应该试试
file_get_contents -
你能告诉我怎么做吗
标签: json google-maps google-api