使用php使用json解析来自google maps api v3的数据

使用php使用json解析来自google maps api v3的数据,php,json,google-maps,parsing,Php,Json,Google Maps,Parsing,我想通过json解析谷歌地图地理代码第3版中的数据。我想获得详细信息,如locaityName、AdministrativeAreaName和状态代码。我可以知道如何解析这些数据吗?谢谢您可以使用json_encode和json_decode函数解析json数据 更多信息: PHP具有将JSON数据流转换为PHP数组或对象的功能。使用PHP PECL JSON库 json_decode() 只是一个建议,如果函数没有返回任何表示JSON中存在语法错误的内容,它将不会引发任何错误或日志。我想解

我想通过json解析谷歌地图地理代码第3版中的数据。我想获得详细信息,如locaityName、AdministrativeAreaName和状态代码。我可以知道如何解析这些数据吗?谢谢

您可以使用
json_encode
json_decode
函数解析json数据

更多信息:


PHP具有将JSON数据流转换为PHP数组或对象的功能。

使用PHP PECL JSON库

json_decode()


只是一个建议,如果函数没有返回任何表示JSON中存在语法错误的内容,它将不会引发任何错误或日志。

我想解析上面提到的google geocode中的特定数据。你知道解析这些数据的结构吗?谢谢。@ben,你为什么不提出一个请求,然后使用
print\r()
?这是最简单的方法,我想从上面提到的谷歌地理代码中解析特定的数据。你知道解析这些数据的结构吗?谢谢,伙计,2年后,仍然没有人直接回答你的问题。
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;
    }