(未显示1个用户的1个中间版本) | |||
第7行: | 第7行: | ||
rateLimit=是| | rateLimit=是| | ||
params= | params= | ||
− | {{api_args|json|true|string|特殊的JSON参数形式,使用方法如下,见注意事项。}}| | + | {{api_args|json|true|string|特殊的JSON参数形式,使用方法如下,见注意事项。}} |
+ | | | ||
+ | |||
apiToolPara=key1=json&value1=JSON格式参数,见wiki文档注意事项| | apiToolPara=key1=json&value1=JSON格式参数,见wiki文档注意事项| | ||
+ | relat_qa=<html><div id="relat_qa" data="location/mobile/get_location"></div></html>| | ||
result= | result= | ||
<pre> | <pre> | ||
第36行: | 第39行: | ||
<pre> | <pre> | ||
{ | { | ||
− | "version": " | + | "version": "2.0", //请求版本信息 |
− | "host": "api.weibo.com/2/location/mobile/get_location", | + | "host": "api.weibo.com", //请求地址信息 |
+ | "radio_type": "gsm", //请求类型 | ||
+ | "request_address": true, //是否需要返回详细地址,可选,默认:false | ||
+ | "decode_pos": true, //返回坐标是否偏移处理,偏移后坐标适合在新浪地图上使用(http://map.sina.com.cn), | ||
+ | //不适用于百度地图(各地图偏移量不同,请谨慎处理);可选,默认:false | ||
+ | "ip": "202.106.182.111", //请求ip 可选 | ||
+ | "location": { //GPS设备获得的本地经纬度,可选,如果没有请一定删除此项,否则可能影响数据准确度 | ||
+ | "latitude": "39.08943", //纬度 | ||
+ | "longitude": "116.36843", //经度 | ||
+ | "accuracy": "678.0" //准确度 | ||
+ | }, | ||
+ | "cell_towers": [ //基站信息 | ||
+ | { | ||
+ | "cell_id": "4466", //基站号 | ||
+ | "location_area_code": "26630", //小区号 | ||
+ | "mobile_country_code": "460", //地区代码 | ||
+ | "mobile_network_code": "0", //运营商号 | ||
+ | "signal_strength": "-60" //信号强度 | ||
+ | }, | ||
+ | { | ||
+ | "cell_id": "4466", | ||
+ | "location_area_code": "25054", | ||
+ | "mobile_country_code": "460", | ||
+ | "mobile_network_code": "0", | ||
+ | "signal_strength": "-70" | ||
+ | }, | ||
+ | ... | ||
+ | ], | ||
+ | "wifi_towers": [ //WIFI信息 | ||
+ | { | ||
+ | "mac_address": "00:0B:86:27:99:B0", | ||
+ | "mac_name": "cnc", | ||
+ | "signal_strength": "78" //信号强度 | ||
+ | }, | ||
+ | { | ||
+ | "mac_address": "00:0B:86:28:7B:F0", | ||
+ | "mac_name": "CMCC", | ||
+ | "signal_strength": "90" | ||
+ | }, | ||
+ | ... | ||
+ | ] | ||
+ | } | ||
+ | </pre> | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | *调用举例 | ||
+ | |||
+ | |||
+ | <pre> | ||
+ | <?php | ||
+ | //改为你的微博账号,用户名和密码之间用:隔开 | ||
+ | $userPwd = 'wjschaoren@sina.com:xxxxxx'; | ||
+ | //改为你微博应用的appkey | ||
+ | $appkey = '1601334720'; | ||
+ | $url = "https://api.weibo.com/2/location/mobile/get_location.json?source=$appkey"; | ||
+ | //data为json格式数据 | ||
+ | $data = ' | ||
+ | { | ||
+ | "version": "2.0", | ||
+ | "host": "api.weibo.com", | ||
"radio_type": "gsm", | "radio_type": "gsm", | ||
"request_address": true, | "request_address": true, | ||
"decode_pos": true, | "decode_pos": true, | ||
− | "ip": " | + | "ip": "202.106.182.111", |
"location": { | "location": { | ||
"latitude": "39.08943", | "latitude": "39.08943", | ||
第61行: | 第125行: | ||
"mobile_network_code": "0", | "mobile_network_code": "0", | ||
"signal_strength": "-70" | "signal_strength": "-70" | ||
− | } | + | } |
− | + | ||
], | ], | ||
"wifi_towers": [ | "wifi_towers": [ | ||
第74行: | 第137行: | ||
"mac_name": "CMCC", | "mac_name": "CMCC", | ||
"signal_strength": "90" | "signal_strength": "90" | ||
− | } | + | } |
− | + | ||
] | ] | ||
+ | } | ||
+ | '; | ||
+ | //注意一定要加json头 | ||
+ | $header = array('Content-type: application/json'); | ||
+ | $rst = curlSample($url,$userPwd,$data,$header); | ||
+ | echo $rst; | ||
+ | function curlSample($url,$userPwd,$postFields = '',$header = ''){ | ||
+ | $ch = curl_init() or die (curl_error()) ; | ||
+ | curl_setopt($ch,CURLOPT_URL,$url); | ||
+ | curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); | ||
+ | curl_setopt($ch,CURLOPT_TIMEOUT,3); | ||
+ | if(!empty($userPwd)){ | ||
+ | curl_setopt($ch,CURLOPT_USERPWD,$userPwd); | ||
+ | } | ||
+ | if(!empty($postFields)){ | ||
+ | curl_setopt($ch,CURLOPT_POST,true); | ||
+ | curl_setopt($ch,CURLOPT_POSTFIELDS,$postFields); | ||
+ | } | ||
+ | if(!empty($header)){ | ||
+ | curl_setopt($ch, CURLOPT_HTTPHEADER,$header); | ||
+ | } | ||
+ | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); | ||
+ | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); | ||
+ | $result = curl_exec($ch) or die (curl_error($ch)); | ||
+ | curl_close($ch); | ||
+ | return $result; | ||
} | } | ||
− | </pre>| | + | ?> |
+ | </pre> | ||
+ | |||
+ | | | ||
otherInfo=目前定位服务只支持中国大陆地区; | otherInfo=目前定位服务只支持中国大陆地区; | ||
}}{{#a:showgrade}} | }}{{#a:showgrade}} |
2013年5月7日 (二) 13:55的最后版本
location/mobile/get_location
根据移动基站WIFI等数据获取当前位置信息
URL
https://api.weibo.com/2/location/mobile/get_location.json
支持格式
JSON
HTTP请求方式
POST
是否需要登录
是
关于登录授权,参见 如何登录授权
访问授权限制
访问级别:普通接口
频次限制:是
关于频次限制,参见 接口访问权限说明
请求参数
必选 | 类型及范围 | 说明 | |
---|---|---|---|
access_token | true | string | 采用OAuth授权方式为必填参数,OAuth授权后获得。 |
json | true | string | 特殊的JSON参数形式,使用方法如下,见注意事项。 |
注意事项
- 该接口请求参数需要以JSON格式,用POST请求方式发送;
- 发送请求的Content-Type必须为application/json;
- 发送的JSON格式参数的数据必须如下:
{ "version": "2.0", //请求版本信息 "host": "api.weibo.com", //请求地址信息 "radio_type": "gsm", //请求类型 "request_address": true, //是否需要返回详细地址,可选,默认:false "decode_pos": true, //返回坐标是否偏移处理,偏移后坐标适合在新浪地图上使用(http://map.sina.com.cn), //不适用于百度地图(各地图偏移量不同,请谨慎处理);可选,默认:false "ip": "202.106.182.111", //请求ip 可选 "location": { //GPS设备获得的本地经纬度,可选,如果没有请一定删除此项,否则可能影响数据准确度 "latitude": "39.08943", //纬度 "longitude": "116.36843", //经度 "accuracy": "678.0" //准确度 }, "cell_towers": [ //基站信息 { "cell_id": "4466", //基站号 "location_area_code": "26630", //小区号 "mobile_country_code": "460", //地区代码 "mobile_network_code": "0", //运营商号 "signal_strength": "-60" //信号强度 }, { "cell_id": "4466", "location_area_code": "25054", "mobile_country_code": "460", "mobile_network_code": "0", "signal_strength": "-70" }, ... ], "wifi_towers": [ //WIFI信息 { "mac_address": "00:0B:86:27:99:B0", "mac_name": "cnc", "signal_strength": "78" //信号强度 }, { "mac_address": "00:0B:86:28:7B:F0", "mac_name": "CMCC", "signal_strength": "90" }, ... ] }
- 调用举例
<?php //改为你的微博账号,用户名和密码之间用:隔开 $userPwd = 'wjschaoren@sina.com:xxxxxx'; //改为你微博应用的appkey $appkey = '1601334720'; $url = "https://api.weibo.com/2/location/mobile/get_location.json?source=$appkey"; //data为json格式数据 $data = ' { "version": "2.0", "host": "api.weibo.com", "radio_type": "gsm", "request_address": true, "decode_pos": true, "ip": "202.106.182.111", "location": { "latitude": "39.08943", "longitude": "116.36843", "accuracy": "678.0" }, "cell_towers": [ { "cell_id": "4466", "location_area_code": "26630", "mobile_country_code": "460", "mobile_network_code": "0", "signal_strength": "-60" }, { "cell_id": "4466", "location_area_code": "25054", "mobile_country_code": "460", "mobile_network_code": "0", "signal_strength": "-70" } ], "wifi_towers": [ { "mac_address": "00:0B:86:27:99:B0", "mac_name": "cnc", "signal_strength": "78" }, { "mac_address": "00:0B:86:28:7B:F0", "mac_name": "CMCC", "signal_strength": "90" } ] } '; //注意一定要加json头 $header = array('Content-type: application/json'); $rst = curlSample($url,$userPwd,$data,$header); echo $rst; function curlSample($url,$userPwd,$postFields = '',$header = ''){ $ch = curl_init() or die (curl_error()) ; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_TIMEOUT,3); if(!empty($userPwd)){ curl_setopt($ch,CURLOPT_USERPWD,$userPwd); } if(!empty($postFields)){ curl_setopt($ch,CURLOPT_POST,true); curl_setopt($ch,CURLOPT_POSTFIELDS,$postFields); } if(!empty($header)){ curl_setopt($ch, CURLOPT_HTTPHEADER,$header); } curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); $result = curl_exec($ch) or die (curl_error($ch)); curl_close($ch); return $result; } ?>
调用样例及调试工具
返回结果
JSON示例
{ "location": { "longitude": "116.39794", "latitude": "39.90817", "accuracy": "50", "altitude": "0", "altitude_accuracy": "0", "address": { "city": "11", "province": "32", "city_name": "北京", "province_name": "朝阳区", "district": "朝阳区", "address": "中国北京市海淀区中关村" } } }
关于错误返回值与错误代码,参见 错误代码说明
返回字段说明
无
其他
目前定位服务只支持中国大陆地区;
相关问题
到 帮助中心 查看更多问题或提问
文档更新时间: 2013-05-07