Google Gears提供了一个地理位置API,可以获取LAC-CELLId信息并提供经纬度数据。 该API在此处详述:Geolocation API 我正在使用PHP。下面是我写的代码:通过POST将JSON对象发送给Google Gears时遇到问题
<?php
$urlstring="http://www.google.com/loc/json";
$ch=curl_init($urlstring);
$cell_towers = array();
$row=new stdClass();
$row->location_area_code=3311;
$row->mobile_network_code=71;
$row->cell_id=32751;
$row->mobile_country_code=404;
$cell_towers[]=$row;
$param = array(
'host'=> 'localhost',
'version' => '1.1.0',
'request_address' => true,
'cell_towers' => $cell_towers
);
$param_json=json_encode($param);
//echo $param_json."<br />";
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,urlencode($param_json));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("application/jsonrequest"));
$result=curl_exec($ch);
echo $result;
>
,我得到的是响应“JSON解析错误。” 我在做什么错?
该死!非常感谢,这让我非常开心。删除urlencode修复了它。 – citsym 2011-04-19 12:19:32