How to get Baidu coordinate api returned json format string or object json is not very familiar, such as calling this interface http://api.map.baidu.com/ag/coord/convert? From = 2 & amp; to = 4 & amp; x = 116.40624058825688 & amp; y = 39. how to get the json format string or object returned by Baidu coordinate api?
Json is not very familiar, such as calling this interface http://api.map.baidu.com/ag/coord/convert? From = 2 & to = 4 & x = 116.40624058825688 & y = 39.90789300648029 & callback = callback the returned data is callback & callback ({"error": 0, "x": "MTE2LjQxMjYxOTYwMDc1", "y": "MzkuOTE0MjIxMTQyNDM3 "})
If you want to obtain the encrypted data after x and y, pay attention to the fact that there are many coordinates and you need to batch
It is best to write an example. Baidu shares the following JSON callback API:
------ Solution --------------------
$url = 'http://api.map.baidu.com/ag/coord/convert?from=2&to=4&x=116.40624058825688&y=39.90789300648029&callback=callback';
$s = file_get_contents($url);
strtok($s, '(');
$t = json_decode(strtok(')'), 1);
$t['x'] = base64_decode($t['x']);
$t['y'] = base64_decode($t['y']);
print_r($t);
Array
(
[Error] => 0
[X] = & gt; 116.41261960075
[Y] = & gt; 39.914221142437
)
------ Solution --------------------
print_r( json_decode('{"error":0,"x":"MTE2LjQxMjYxOTYwMDc1","y":"MzkuOTE0MjIxMTQyNDM3"}',true));
Array
(
[Error] => 0
[X] => MTE2LjQxMjYxOTYwMDc1
[Y] => MzkuOTE0MjIxMTQyNDM3
)
The values after x and y are base64 encrypted.
------ Solution --------------------
This is php timeout.
Run set_time_limit (0 );
------ Solution --------------------
The second parameter of json_decode indicates whether the object is returned using an array. the default parameter is