您的位置:首页 > 编程语言 > Go语言

获取移动手機基站ID并通过google API获取经纬度等参数

2012-02-14 16:35 761 查看
1、如何获取移动手機基站ID?

对于这个东西,既然是手機基站ID,当然只能通过手機获取,所以建议你先了解手機软件这块的东西。

2、学习google api中的“Geolocation API Network Protocol”。

Geolocation API Network Protocol 是GOOGLE API提供的一个接口,主要功能是发送基站ID/WiFi信息给google api,然后api返回一些列参数,在这些参数中就包括了目标的经纬度。

好了,我们进入正题,主要是给一个PHP Demo 源码。以下源码中部分函数需要php5+支持,还有我封装的curl函数(curl.func.php)

<?php
/*
Desc: 提交请求参数 Request
version string google api 版本[必]
host string 服务器域名[必]
home_mobile_country_code integer 移动用户所属国家代号[选 中国460]
home_mobile_network_code integer 移动系统号码[选 默认0]
address_language string 反馈数据语言[选 中国 zh_CN]
radio_type string 信号类型[选 gsm|cdma|wcdma]
request_address bool 是否返回数据[必]
cell_towers object 移动基站参数对象[必]
cell_id integer 基站ID[必]
location_area_code integer 地区区域码[必]
age integer 使用好久的数据库[选 默认0表示使用最新的数据库]
timing_advance integer 距离单位
*/
require(ROOT . 'include/curl.func.php');//加载封装好的curl函数库
if(function_exists(json_decode)) {//判断服务器是否支持json_decode函数
$post_data ='
{
"version": "1.1.0",
"host": "www.ipkaka.com",
"home_mobile_country_code": "460",
"home_mobile_network_code": "0",
"address_language": "zh_CN",
"radio_type": "gsm",
"request_address": true ,
"cell_towers":[
{
"cell_id": "2663",
"location_area_code": "32902",
"age": "0",
"timing_advance": "5555"
}
]
}
';
$data = array(
'url' => 'http://www.google.com/loc/json',//google API地址URL,注意请求一定要是Json格式
'post' => $post_data,
);
$arr_post_result = ns_curl($data);//curl POST 过去,返回一个数组
$result_html = $arr_post_result['html'];//API返回中有效东西,格式是JSON
$result_code = $arr_post_result['http_code'];
$obj_return_info = json_decode($result_html);//对Json解密,返回的是对象,请注意
if(is_object($obj_return_info) && !empty($obj_return_info) && $result_code == 200) {
object2array($obj_return_info); //object2array 递归对象转数组
$arr_api_info = $obj_return_info;
$obj_return_info = null;//杀掉内存中的无效变量
$latitude = $arr_api_info['location']['latitude']; //纬度
$longitude = $arr_api_info['location']['longitude']; //经度
$country = $arr_api_info['location']['address']['country']; //国家名称
$country_code = strtolower($arr_api_info['location']['address']['country_code']); //国家简写 CN
$region = $arr_api_info['location']['address']['region']; //省
$city = $arr_api_info['location']['address']['city']; //市
$street = $arr_api_info['location']['address']['street']; //街道
$accuracy = $arr_api_info['location']['accuracy']; //误差 单位meters
$access_token = $arr_api_info['access_token']; //连接值
print_r($longitude);
}
}
/*
Desc: google api 返回参数demo
Array
(
[location] => Array
(
[latitude] => 30.644389
[longitude] => 104.08439
[address] => Array
(
[country] => 中国
[country_code] => CN
[region] => 四川省
[city] => 成都市
[street] => 黄伞巷
)

[accuracy] => 723
)

[access_token] => 2:mqs0Jw83vIzz0OG2:pbCXuys2oe6pJgLy
)
*/
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: