我使用此代码返回Google API地点数据:
<?php
error_reporting(E_ALL);
ini_set("display_errors", true);
include_once 'configuration.php';
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'https://maps.googleapis.com/maps/api/place/textsearch/json?query=restaurants+in+Sydney&key='.API_KEY);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Your application name');
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json')
);
$result = curl_exec($curl_handle);
curl_close($curl_handle);
echo $result;
但是我得到了这样的无格式数据:
{“html_attributions”:[],“next_page_token”: “CpQCBgEAAPvFBhJiIaT9iMCS-miiTKEXeY0Gkdt3psd0DiGaza6x7U_NCaLCCoc6avQy7_VepOtrke7oIfrXC2MFkeDmD2DJt3Hi5j4IEmHyY9lTT0JkvRRLW043khKMhAiz6U5fdG-Ylkp7Uq3E_jWjOjgSoR7sBbTzVcn_PuzeKcRcwHtyV2h-ZpCwY-YH7wBiKogPvrwQYCWN_scs5ZWsoJSgELFFFfvl-oaL6OXCERv1fZM6opKvri1GMK6_aEYjnj4pR92PjJNWaAeroixITFGoj5RDVS4MNPVd-60jdG83ET0JU-XsjiY7TdipReos7gbKQR8eJXZho11sOLKGtTATOVCzPZYpzsbvjFgpzMzAoyEFEhCtyjb8l0hKpZAXk7rKoe4NGhSVJjiMIqDyQPH0hVYJg-IX1p2Rvw” “结果”:[{“formatted_address”:“529 Kent St,Sydney NSW 2000, 澳大利亚“,”几何“:{”location“:{”lat“: - 33.875154,”lng“: 151.204976},“viewport”:{“northeast”:{“lat”: - 33.87374772010728,“lng”:151.2065219798927},“southwest”:{“lat”: - 33.87644737989272,“lng”:151.2038223201073}}},“icon “: “https://maps.gstatic.com/mapfiles/place_api/icons/restau
我需要采用这种格式: