How can I obtain a json string or object returned by Baidu coordinate api?

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.