谷歌提供的json数据会根据可用数据不断变化。有时会有一个位置字符串,但对于某些纬度/经度,没有位置信息。是否有经验法则或某些包装类可以从所有可能的json字符串中提取城市和国家?
例如http://maps.google.com/maps/geo?q=24.487148563173424,-78.046875&output=json给了我
{
"name": "24.487148563173424,-78.046875",
"Status": {
"code": 200,
"request": "geocode"
},
"Placemark": [ {
"id": "p1",
"address": "Central Andros, The Bahamas",
"AddressDetails": {
"Accuracy" : 3,
"Country" : {
"CountryName" : "The Bahamas",
"CountryNameCode" : "BS",
"SubAdministrativeArea" : {
"SubAdministrativeAreaName" : "Central Andros"
}
}
},
"ExtendedData": {
"LatLonBox": {
"north": 24.6312368,
"south": 24.3062499,
"east": -77.7177462,
"west": -78.2299838
}
},
"Point": {
"coordinates": [ -77.9738650, 24.4688482, 0 ]
}
} ]
}
http://maps.google.com/maps/geo?q=47.33882269482199,-100.634765625&output=json给我的地方
{
"name": "47.33882269482199, -100.634765625",
"Status": {
"code": 200,
"request": "geocode"
},
"Placemark": [ {
"id": "p1",
"address": "11445 471st Ave NE, McClusky, ND 58463, USA",
"AddressDetails": {
"Accuracy" : 8,
"Country" : {
"AdministrativeArea" : {
"AdministrativeAreaName" : "ND",
"SubAdministrativeArea" : {
"Locality" : {
"LocalityName" : "McClusky",
"PostalCode" : {
"PostalCodeNumber" : "58463"
},
"Thoroughfare" : {
"ThoroughfareName" : "11445 471st Ave NE"
}
},
"SubAdministrativeAreaName" : "Sheridan"
}
},
"CountryName" : "USA",
"CountryNameCode" : "US"
}
},
"ExtendedData": {
"LatLonBox": {
"north": 47.3307737,
"south": 47.3244785,
"east": -100.6025856,
"west": -100.6089256
}
},
"Point": {
"coordinates": [ -100.6089257, 47.3276298, 0 ]
}
} ]
}
是否有一些标准程序可以获取城市和国家名称? 我正在穿越json,试图处理gogole向我投掷的不同格式。
由于
答案 0 :(得分:0)
您可以尝试寻找合适的解析器来提取该信息吗?
修改强>
http://www.devshed.com/c/a/PHP/Parsing-Google-Maps-API-using-PHP-and-JSON-2348127/
我相信这对你的解析器是一个很好的阅读