备忘--基站定位技术(转载)

    技术2025-09-01  18

    很多朋友在使用google GeolocationAPI 接口测试基站定位,测试时需要往接口http://www.google.com/loc/json提交json格式的数据,json格式参数比较多,在IDE里测试起来也比较麻烦,有时因为一个语法错误不得不排查很长时间。

    这里ant 推荐一个比较简单的方法来测试json数据格式是否正确:使用curl测试。

    curl 是一个利用URL语法在命令行方式下工作的文件传输工具。使用curl来提交http GET/POST数据很是方便。curl是Unix/Linux下常用的工具,也有windows版本 。

    GeolocationAPI 的详细语法这里就不介绍了。

    例如我们想通过http://www.google.com/loc/json查询LAC:14556 ,CELLID:36525 的基站位置。根据GeolocationAPI 里提到的语法,提交的数据应该是这样的格式:

    { "version": "1.1.0" , "host": "maps.google.com", "access_token": "2:k7j3G6LaL6u_lafw:4iXOeOpTh1glSXe", "home_mobile_country_code": 460, "home_mobile_network_code":0, "address_language": "zh_CN", "radio_type": "gsm", "request_address": true , "cell_towers":[ { "cell_id":36526, "location_area_code":14556, "mobile_country_code":460, "mobile_network_code":0, "timing_advance":5555 } ] }

    下面我们通过curl测试该格式是否正确。

    命令格式: curl -d ‘post的数据’ http://www.google.com/loc/json

    这里只需要用到curl的-d参数,-d后面跟的是post的数据内容

    在命令行下输入” curl -d ‘ “后回车,粘贴上面的json格式数据回车,再输入” ‘ http://www.google.com/loc/json”回车,就可以看到google的返回结果了。

    通过curl可以方便的测试各种json参数组合。

     

     

     

     

     

     

    更具以上接口说明,我写了以下可用代码

    <?php     function curl_post($url, $vars, $second=30)     {         $ch = curl_init();         curl_setopt($ch,CURLOPT_TIMEOUT,$second);         curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);         curl_setopt($ch,CURLOPT_URL,$url);         curl_setopt($ch,CURLOPT_POST, 1);         curl_setopt($ch,CURLOPT_POSTFIELDS,$vars);         $data = curl_exec($ch);         curl_close($ch);         return $data;     }          $vars = '{ "version": "1.1.0" , "host": "maps.google.com", "access_token": "2:k7j3G6LaL6u_lafw:4iXOeOpTh1glSXe", "home_mobile_country_code": 460, "home_mobile_network_code":0, "address_language": "zh_CN", "radio_type": "gsm", "request_address": true , "cell_towers":[ { "cell_id":36526, "location_area_code":14556, "mobile_country_code":460, "mobile_network_code":0, "timing_advance":5555 } ] }';     $rdata = curl_post('http://www.google.com/loc/json',$vars);     $r_ary = (array) json_decode($rdata);     print_r($r_ary['location']); ?>

    最新回复(0)