我想解析从谷歌地图地理编码版本3通过JSON数据。我想获得详细信息,如locaityName,AdministrativeAreaName和状态码。我可以知道如何解析这些数据吗?谢谢解析数据从谷歌地图API与PHP与JSON与PHP
2
A
回答
0
PHP有json_decode(),将一个JSON数据流转换为PHP数组或对象。
0
+0
我想解析来自google地理编码的具体数据,就像我上面提到的那样。你知道解析这些数据的结构吗?谢谢。 – davidlee 2010-04-24 10:11:18
0
使用PHP PECL JSON库
json_decode()
http://php.net/manual/en/function.json-encode.php
只是一个建议,如果函数不返回任何东西,这意味着有一个语法错误为JSON,它不会提高任何错误或日志。
3
function getGoogleAddressCoordinates()
{
//using the google maps api to get the long and lat coordinates of addresss
//using form post variables
$address =trim($_POST['address']);
$city = trim($_POST['city']);
$state = trim($_POST['state']);
//formats the address add '+' into space
$address = str_replace(' ', '+' ,$address);
$city = str_replace(' ', '+', $city);
$address = preg_replace("[^A-Za-z0-9]", '+', $address); //remove non alpha numeric chars such as extra spaces.
$address_str = $address.',+'. $city.',+'.$state;
$geo_url = "http://maps.google.com/maps/api/geocode/json?address=$address_str&sensor=false";
//echo $geo_url;
//echo file_get_contents($geo_url);
$json_result = json_decode(file_get_contents($geo_url));
$geo_result = $json_result->results[0];
$coordinates = $geo_result->geometry->location;
//see if the it is locating the real address or just apox location, or in most cases a bad address
if($geo_result->types[0] == 'street_address')
$coordinates->valid_address = TRUE;
else
$coordinates->valid_address = FALSE;
return $coordinates;
}
相关问题
- 1. 谷歌图与PHP JSON
- 2. 解析pinterest JSON API与PHP
- 3. 谷歌地图API与PHP集成
- 4. 谷歌地图与php
- 5. 解析谷歌图像API Json PHP
- 6. PHP $ json的谷歌地图解析
- 7. JSON解析与谷歌,GSON
- 8. JSON解析与PHP
- 9. 谷歌分析与PHP
- 10. 解析谷歌地图与过滤器
- 11. 与谷歌地图API
- 12. 与谷歌地图API
- 13. 从PHP解析JSON数组与AJAX
- 14. 从数组解析json值与PHP
- 15. 解析JSON响应与谷歌JSON
- 16. 从谷歌地图解析json数据使用php调用mysql数据库
- 17. 与谷歌图表API和PHP
- 18. 解析PHP数据与jsoup
- 19. 与谷歌地图使用PHP
- 20. 多个谷歌地图标记与PHP
- 21. 谷歌地图标记与JavaScript和PHP
- 22. 谷歌地图与PHP的MySQL
- 23. 谷歌地图网关超时与PHP
- 24. 谷歌地图与Php到Js变量
- 25. JSON解析与PHP foreach
- 26. JSON解析与PHP失败
- 27. 解析谷歌翻译与PHP的json_decode()V2 JSON
- 28. 解析谷歌地图API
- 29. JSON API与PHP/PHP
- 30. IOS地图(谷歌地图API与MapKit?)
男人,2年后,仍然没有人直接回答你的问题。 – Ray 2012-08-07 18:56:29