android 基站分布,android 基站定位
这里给大家分享下基站定位的实现,基站定位首先要通过TelephonyManager得到手机的信号信息,比如基站的国家编码,小区id等......得到这些后需要向google提供的接口提交这些参数,然后就会返回基站的相关信息。
废话不多说直接上代码吧:
importjava.io.Serializable;
importjava.util.ArrayList;
importjava.util.List;
importandroid.content.Context;
importandroid.telephony.NeighboringCellInfo;
importandroid.telephony.TelephonyManager;
importandroid.telephony.cdma.CdmaCellLocation;
importandroid.telephony.gsm.GsmCellLocation;
importandroid.util.Log;
/**
* @author yangzhiqiang
*
*/
publicclassCellIdInfoManagerimplementsSerializable {
/**
*
*/
privatestaticfinallongserialVersionUID = 5481154371450408380L;
privateContext context;
publicCellIdInfoManager(Context context) {
super();
this.context = context;
}
publicList getCellInfo() {
List listInfo =newArrayList();
intcountryCode;
intnetworkCode;
intareaCode;
CellInfo info =newCellInfo();
GsmCellLocation gsm =null;
TelephonyManager manager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
if(manager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
gsm = (GsmCellLocation) manager.getCellLocation();
if(gsm ==null) {
returnnull;
}
if(manager.getNetworkOperator() ==null
|| manager.getNetworkOperator().length() ==0) {
returnnull;
}
countryCode = Integer.parseInt(manager.getNetworkOperator()
.substring(0,3));
networkCode = Integer.parseInt(manager.getNetworkOperator()
.substring(3,5));
areaCode = gsm.getLac();
info.cellId = gsm.getCid();
info.mobileCountryCode = countryCode;
info.mobileNetworkCode = networkCode;
info.locationAreaCode = areaCode;
info.radio_type ="gsm";
listInfo.add(info);
List list = manager.getNeighboringCellInfo();
for(NeighboringCellInfo i : list) {
CellInfo ci =newCellInfo();
ci.cellId = i.getCid();
ci.mobileCountryCode = countryCode;
ci.mobileNetworkCode = networkCode;
ci.locationAreaCode = areaCode;
ci.radio_type ="gsm";
listInfo.add(ci);
}
}elseif(manager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {
CdmaCellLocation cdma = (CdmaCellLocation) manager
.getCellLocation();
if(cdma ==null) {
returnnull;
}
if(manager.getNetworkOperator() ==null
|| manager.getNetworkOperator().length() ==0) {
returnnull;
}
Log.v("TAG","CDMA");
info.cellId = cdma.getBaseStationId();
info.mobileCountryCode = Integer.parseInt(manager
.getNetworkOperator());
info.mobileNetworkCode = cdma.getSystemId();
info.locationAreaCode = cdma.getNetworkId();
info.radio_type ="cdma";
listInfo.add(info);
}
returnlistInfo;
}
publicclassCellInfo {
// 基站编号
publicintcellId;
// 国家代码
publicintmobileCountryCode;
// 网络代码
publicintmobileNetworkCode;
// 区域代码
publicintlocationAreaCode;
publicString radio_type;
publicCellInfo() {
super();
}
}
}
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.telephony.NeighboringCellInfo;
import android.telephony.TelephonyManager;
import android.telephony.cdma.CdmaCellLocation;
import android.telephony.gsm.GsmCellLocation;
import android.util.Log;
/**
* @author yangzhiqiang
*
*/
public class CellIdInfoManager implements Serializable {
/**
*
*/
private static final long serialVersionUID = 5481154371450408380L;
private Context context;
public CellIdInfoManager(Context context) {
super();
this.context = context;
}
public List getCellInfo() {
List listInfo = new ArrayList();
int countryCode;
int networkCode;
int areaCode;
CellInfo info = new CellInfo();
GsmCellLocation gsm = null;
TelephonyManager manager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
if (manager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
gsm = (GsmCellLocation) manager.getCellLocation();
if (gsm == null) {
return null;
}
if (manager.getNetworkOperator() == null
|| manager.getNetworkOperator().length() == 0) {
return null;
}
countryCode = Integer.parseInt(manager.getNetworkOperator()
.substring(0, 3));
networkCode = Integer.parseInt(manager.getNetworkOperator()
.substring(3, 5));
areaCode = gsm.getLac();
info.cellId = gsm.getCid();
info.mobileCountryCode = countryCode;
info.mobileNetworkCode = networkCode;
info.locationAreaCode = areaCode;
info.radio_type = "gsm";
listInfo.add(info);
List list = manager.getNeighboringCellInfo();
for (NeighboringCellInfo i : list) {
CellInfo ci = new CellInfo();
ci.cellId = i.getCid();
ci.mobileCountryCode = countryCode;
ci.mobileNetworkCode = networkCode;
ci.locationAreaCode = areaCode;
ci.radio_type = "gsm";
listInfo.add(ci);
}
} else if (manager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {
CdmaCellLocation cdma = (CdmaCellLocation) manager
.getCellLocation();
if (cdma == null) {
return null;
}
if (manager.getNetworkOperator() == null
|| manager.getNetworkOperator().length() == 0) {
return null;
}
Log.v("TAG", "CDMA");
info.cellId = cdma.getBaseStationId();
info.mobileCountryCode = Integer.parseInt(manager
.getNetworkOperator());
info.mobileNetworkCode = cdma.getSystemId();
info.locationAreaCode = cdma.getNetworkId();
info.radio_type = "cdma";
listInfo.add(info);
}
return listInfo;
}
public class CellInfo {
// 基站编号
public int cellId;
// 国家代码
public int mobileCountryCode;
// 网络代码
public int mobileNetworkCode;
// 区域代码
public int locationAreaCode;
public String radio_type;
public CellInfo() {
super();
}
}
}
上面是得到手机信号的信息,下面是将这些信息发送到google服务器并解析结果:
importjava.io.BufferedReader;
importjava.io.InputStreamReader;
importjava.io.Serializable;
importjava.util.List;
importorg.apache.http.HttpEntity;
importorg.apache.http.HttpResponse;
importorg.apache.http.HttpStatus;
importorg.apache.http.client.methods.HttpPost;
importorg.apache.http.entity.StringEntity;
importorg.apache.http.impl.client.DefaultHttpClient;
importorg.json.JSONArray;
importorg.json.JSONObject;
importandroid.location.Location;
importandroid.util.Log;
importcom.metarnet.gps.CellIdInfoManager.CellInfo;
/**
* @author Administrator
*
*/
publicclassNetworkLocationManagerimplementsSerializable {
/**
*
*/
privatestaticfinallongserialVersionUID = 1185788569820321281L;
publicstaticLocation getBaseStationLocation(List cellID) {
if(cellID ==null) {
Log.i("TAG","cellId is null.");
returnnull;
}
DefaultHttpClient client =newDefaultHttpClient();
HttpPost post =newHttpPost("http://www.google.com/loc/json");
JSONObject holder =newJSONObject();
try{
CellInfo info = cellID.get(0);
holder.put("version","1.1.0");
holder.put("host","maps.google.com");
holder.put("home_mobile_country_code", info.mobileCountryCode);
holder.put("home_mobile_network_code", info.mobileNetworkCode);
holder.put("request_address",true);
holder.put("radio_type", info.radio_type);
if("460".equals(info.mobileCountryCode)) {
holder.put("address_language","zh_CN");
}else{
holder.put("address_language","en_US");
}
JSONObject data, current_data;
JSONArray array =newJSONArray();
current_data =newJSONObject();
current_data.put("cell_id", info.cellId);
current_data.put("location_area_code", info.locationAreaCode);
current_data.put("mobile_country_code", info.mobileCountryCode);
current_data.put("mobile_network_code", info.mobileNetworkCode);
current_data.put("age",0);
array.put(current_data);
if(cellID.size() >2) {
for(inti =1; i
data =newJSONObject();
data.put("cell_id", info.cellId);
data.put("location_area_code", info.locationAreaCode);
data.put("mobile_country_code", info.mobileCountryCode);
data.put("mobile_network_code", info.mobileNetworkCode);
data.put("age",0);
array.put(data);
}
}
holder.put("cell_towers", array);
StringEntity se =newStringEntity(holder.toString());
post.setEntity(se);
HttpResponse resp = client.execute(post);
intstate = resp.getStatusLine().getStatusCode();
if(state == HttpStatus.SC_OK) {
HttpEntity entity = resp.getEntity();
if(entity !=null) {
BufferedReader br =newBufferedReader(
newInputStreamReader(entity.getContent()));
StringBuffer sb =newStringBuffer();
String resute ="";
while((resute = br.readLine()) !=null) {
sb.append(resute);
}
br.close();
data =newJSONObject(sb.toString());
data = (JSONObject) data.get("location");
Location loc =newLocation(
android.location.LocationManager.NETWORK_PROVIDER);
loc.setLatitude((Double) data.get("latitude"));
loc.setLongitude((Double) data.get("longitude"));
loc.setAccuracy(Float.parseFloat(data.get("accuracy")
.toString()));
loc.setTime(System.currentTimeMillis());
returnloc;
}else{
returnnull;
}
}else{
Log.v("TAG", state +"");
returnnull;
}
}catch(Exception e) {
Log.e("TAG", e.getMessage());
returnnull;
}
}
}
android 基站分布,android 基站定位相关推荐
- Android基站定位——三基站(多基站)定位(三)
转载请标明出处:http://blog.csdn.net/android_ls/article/details/8673532 这一篇基于:Android基站定位--单基站定位(二) 阐述几个概念: ...
- 使用android 手机做附近基站的扫描
最近做了一个扫描附近基站的小程序,其中遇到一些参数什么的.这里记录一下: 使用android手机获取附近基站信息 前提是需要有手机卡 telephonyManager = (TelephonyMana ...
- Android有官方的GPS定位API,为什么还要使用百度/高德定位SDK ?
1. 背景 小组在一个Demo项目中,图省事准备使用官方的GPS定位API. 但在我的印象中,官方的定位API是不好用的,一般都是用 高德地图/百度地图 的定位SDK的. 使用官方的定位API获取定位 ...
- [android] 百度地图开发 (二).定位城市位置和城市POI搜索
一. 百度地图城市定位和POI搜索知识 上一篇文章"百度地图开发(一)"中讲述了如何申请百度APIKey及解决显示空白网格的问题.该篇文章主要讲述如何定位城市位置.定位 ...
- Android百度地图之位置定位和附近查找代码简单实现 (上)
很长时间没有做Android相关知识了,闲暇之余再弄了弄最新的百度地图API,主要是进行百度地图附近餐馆查找功能来练练手,同时熟悉下最新的API教程.文章比较基础,也希望对你有所帮助~参考前文: ...
- 基于Android的高德地图的定位和运动轨迹记录的功能
废话不多说,首先去高德地图的API上获取key(这一步很重要),因为没有KEY是无法获取高德地图的. 首先这是高德地图API的网址https://lbs.amap.com/,可以点击进去 ...
- [android] 百度地图开发 (三).定位当前位置及getLastKnownLocation获取location总为空问题
前一篇百度地图开发讲述"(二).定位城市位置和城市POI搜索",主要通过监听对象MKSearchListener类实现城市兴趣点POI(Point of Intere ...
- android室内定位+3d,基于Android平台的手机室内定位及导航的设计与实现
摘要: 随着无线通信网络技术的发展,智能手机逐渐融入到人们的日常生活中.它不仅满足当今人们对于通话短信等基本功能的需求,而且还满足人们对于娱乐.上网.社交等功能的需求.导航功能是现在人们常用的一个功能 ...
- Android 集成高德地图——当前定位,添加图标,画路线,设置显示中心位置,比例,地图刷新位置监听,判断GPS开启,去打开GPS
/*** 判断定位服务是否开启** @param* @return true 表示开启*/ public static boolean isLocationEnabled(Context contex ...
- android 百度地图3.0定位,Android 百度地圖 SDK v3.0.0 (二) 定位與結合方向傳感器...
新功能添加: 第一,定位功能:第二,與方向傳感器結合,通過旋轉手機進行道路的方向確認. 1.初次啟動定位 /** * 定位的客戶端 */ privateLocationClient mLocation ...
最新文章
- python dataframe 分位数_Python pandas.DataFrame.quantile函数方法的使用
- 解决笔记本集成声卡在某些情况下视频、语音没有声音
- MySQL在创建索引之前一定要想到的事情
- linux编译树莓派内核,编译树莓派 4B Linux 5.9 内核
- jquery中ajax请求后台数据成功后既不执行success也不执行error解决方法
- LTE中QPSK、16QAM、64QAM
- RESTful Web 服务 - 消息
- boost::intrusive::list_member_hook用法的测试程序
- Dos 中实现else if 功能
- TypeScript里的中括号类型定义法
- php 如何宏定义,php – 在html中实现宏定义的方法
- python中代理模式分为几种_通俗 Python 设计模式——代理模式
- java标签组件命名_java编程规范之java命名规范
- 钱天财8.25黄金白银在线分析及黄金在线解套
- Ajax请求下载文件
- CentOS安装打字游戏,typespeed
- java实现银行卡卡号 Luhm 校验算法
- 驱动开发笔记3—SSDT表详解
- centos7.2php,Centos7.2之phpadmin安装配置
- 星淘惠告诉你跨境平台那么多,凭什么要选亚马逊?
热门文章
- mysql间隙锁_解决MySQL可重复读——详解间隙锁
- linux云计算7 24,Linux云计算学习笔记day24
- 面向对象软件测试开题报告,软件测试开题报告范文.doc
- ArcGIS软件应用(一)——专题图制作
- [技巧]如何绕过MaxtoCode的15天限制
- 【时间之外】金融数据中心机房应对监管(最新出炉)
- mysql杏林中医诊所管理系统毕业设计源码133742
- 怎么复制黑苹果config配置_只需3步,实现黑苹果USB端口配置
- 中国麻将:世界上最早的区块链项目
- 高考作文也被AI攻克?B站UP主爆肝100天,开发会写高考作文的AI