一,首先普及一下手机基站信息中相关的专业词汇:

通过TelephonyManager 获取lac:mcc:mnc:cell-id(基站信息)的解释:
 MCC,Mobile Country Code,移动国家代码(中国的为460);
 MNC,Mobile Network Code,移动网络号码(中国移动为0,中国联通为1,中国电信为2); 
 LAC,Location Area Code,位置区域码;
 CID,Cell Identity,基站编号;
 BSSS,Base station signal strength,基站信号强度。

二,获取手机卡基站信息(前提需要有手机卡,模拟器无法实现):

 /*** 获取手机基站信息* @throws JSONException */public void getGSMCellLocationInfo() throws JSONException{TelephonyManager manager = (TelephonyManager) mAppMain.getSystemService(Context.TELEPHONY_SERVICE);String operator = manager.getNetworkOperator();/**通过operator获取 MCC 和MNC */int mcc = Integer.parseInt(operator.substring(0, 3));int mnc = Integer.parseInt(operator.substring(3));GsmCellLocation location = (GsmCellLocation) manager.getCellLocation();/**通过GsmCellLocation获取中国移动和联通 LAC 和cellID */int lac = location.getLac();int cellid = location.getCid();/**通过CdmaCellLocation获取中国电信 LAC 和cellID */        /*CdmaCellLocation location1 = (CdmaCellLocation) mTelephonyManager.getCellLocation();     lac = location1.getNetworkId();        cellId = location1.getBaseStationId();         cellId /= 16;*/  int strength = 0;/**通过getNeighboringCellInfo获取BSSS */List<NeighboringCellInfo> infoLists = manager.getNeighboringCellInfo();System.out.println("infoLists:"+infoLists+"     size:"+infoLists.size());for (NeighboringCellInfo info : infoLists) {strength+=(-133+2*info.getRssi());// 获取邻区基站信号强度  //info.getLac();// 取出当前邻区的LAC //info.getCid();// 取出当前邻区的CID System.out.println("rssi:"+info.getRssi()+"   strength:"+strength);}//以下内容是把得到的信息组合成json体,然后发送给我的服务器,获取经纬度信息
     //如果你没有服务器支持,可以发送给BaiduMap,GoogleMap等地图服务商,具体看定位相关的API格式要求JSONObject item = new JSONObject();item.put("cid", cellid);item.put("lac", lac);item.put("mnc", mnc);item.put("mcc", mcc);item.put("strength", strength);JSONArray cells = new JSONArray();cells.put(0, item);JSONObject json = new JSONObject();json.put("cells", cells);CellLocationTask task = new CellLocationTask(json);task.execute();}

三,通过基站信息,请求获取经纬度
CellLocationTask

 /*** 异步请求,通过封装的手机基站信息json体* @author Administrator**/class CellLocationTask extends AsyncTask<String, Void, String>{private JSONObject mJson;private HttpClient mClient;private HttpResponse response;private String responseString;public CellLocationTask(JSONObject json) {this.mJson = json;}@Overrideprotected void onPreExecute() {super.onPreExecute();mClient = new DefaultHttpClient();mClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 15000);mClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 15000);}@Overrideprotected String doInBackground(String... params) {String url = "http://我的服务器地址";try {HttpPost post = new HttpPost(url);post.setEntity(new StringEntity(mJson.toString(), HTTP.UTF_8));post.addHeader("Content-Type", "application/json");response = mClient.execute(post);int statusCode = response.getStatusLine().getStatusCode();System.out.println("doinbackground:"+statusCode);if (statusCode == 200) {responseString  = EntityUtils.toString(response.getEntity());System.out.println("返回结果:"+responseString);}} catch (ClientProtocolException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}return responseString;}@Overrideprotected void onPostExecute(String result) {super.onPostExecute(result);System.out.println("onPostExecute:"+result);JSONObject json;try {json = new JSONObject(result);JSONObject mresult = json.getJSONObject("result");JSONObject geo = mresult.getJSONObject("geo");double lat = geo.getDouble("lat");double lng = geo.getDouble("lng");mLocationGeoPoint = new GeoPoint((int)(lat*1E6), (int)(lng*1E6));CustomOverlay overlay = new CustomOverlay(mAppMain);mMapView.getOverlays().add(overlay);mMapController.animateTo(mLocationGeoPoint);} catch (JSONException e) {e.printStackTrace();}}}

四,地图显示当前位置

CustomOverlay

 class  CustomOverlay extends ItemizedOverlay<OverlayItem>{public CustomOverlay(Context context) throws NumberFormatException, JSONException {super(context.getResources().getDrawable(R.drawable.mylocation));populate();}
     @Overrideprotected OverlayItem createItem(int arg0) {//mLocationGeoPoint为全局变量,CellLocationTask异步得到的经纬度OverlayItem overlayItem = new OverlayItem(mLocationGeoPoint,"", "");return overlayItem;}@Overridepublic int size() {return 1;}@Overridepublic boolean onTap(GeoPoint arg0, MapView arg1) {return super.onTap(arg0, arg1);}}

演示效果:

放到百度地图中,位置有些偏差,这个就需要纠偏了,因为通过基站信息请求到的位置数据并非是百度的数据。以上就是通过基站信息,进行基站定位的实现原理,就是通过MCC,MNC,LAC,CID等属性,请求位置数据,大致就是这个样子。

Android获取手机基站信息并进行基站定位(基站定位原理)相关推荐

  1. Android 获取手机设备信息(厂商,型号等)

    public class DeviceUtils {/*** 获取当前手机系统语言.** @return 返回当前系统语言.例如:当前设置的是"中文-中国",则返回"zh ...

  2. Android获取手机设备信息并区分真机与模拟器

    有些时候我们不想App在模拟器上被别人使用,所以我们禁止在模拟器上使用App 判断是否为真机: 根据以下四图,我们可以对真机与模拟器来做一个简单区分: 如果Serial码为unkonwn或者andro ...

  3. Android 获取手机硬件信息

    /*** 获取当前手机系统语言.** @return 返回当前系统语言.例如:当前设置的是"中文-中国",则返回"zh-CN"*/public static S ...

  4. Android 获取手机设备信息:名称、型号、系统版本号、厂商、设备制造商、SDK版本、系统语言等等

    常用的设备信息获取方法: /*** 设备名称** @return 设备名称*/public static String getDeviceName() {return android.os.Build ...

  5. Android 获取手机通讯录信息 — 头像、姓名和A-Z的快速查询

    首先先看一下效果图再说吧: 具体实现过程如下: 先在AndroidManifest.xml文件中添加读取联系人的权限: 1 <uses-permission android:name=" ...

  6. android获取设备的型号,Android获取手机设备信息

    Android的设备信息获取很简单,导入android.os.Build,在Build类 中有你需要的所有信息. 如果如要经常查阅,可以收藏此文章,需要时点开看一看 下面我打印了一些信息,查查单词的中 ...

  7. Android 获取手机通讯录信息 — 头像、姓名和A-Z的快速查询

    具体实现过程如下: 先在AndroidManifest.xml文件中添加读取联系人的权限: 1 <uses-permission android:name="android.permi ...

  8. Android获取手机品牌信息

    本文的意义在于记录一下主流手机的Build.MANUFACTURER,就不用找手机去跑程序打印log了. String name = Build.MANUFACTURER;L.e(TAG, " ...

  9. android 获取已安装 错误代码,android获取手机已经安装的app信息

    Android获取手机已安装APP(系统/非系统) 效果图 主体代码 private ListView mlistview; private ListpackageInfoList; private ...

  10. Android中获取手机设备信息、RAM、ROM存储信息,如宽、高、厂商名、手机品牌

    借鉴:https://www.jianshu.com/p/ca869aa2fd72 今天有两个工具类总结,代码里都有注释,直接看代码. 一.首先第一个,主要获取手机设备信息DeviceInfoUtil ...

最新文章

  1. 机器学习笔记八:常见“距离”归纳
  2. 看看那些令人惊艳的入库方案
  3. jdbc连接mysql驱动方式_JDBC连接数据库系列教程 – JDBC注册驱动的常见方式
  4. c++ 一日一练:istream.rdbuf(ostringstream.rdbuf())无效!
  5. 道里云在云计算服务隐私安全保障方面的应用
  6. HBase底层存储原理——我靠,和cassandra本质上没有区别啊!都是kv 列存储,只是一个是p2p另一个是集中式而已!...
  7. BZOJ 2751 容易题
  8. dojo使用query dojo/query
  9. 英文版Ubuntu 16.04系统如何解决gedit中文显示乱码的问题
  10. React 学习笔记 —— Ref Hook
  11. Linux学习体会。
  12. java Http post请求发送json字符串
  13. 打造自己的Android源码学习环境之一:序
  14. win10右键删除多余菜单
  15. ReadHub android版
  16. 计算机flash拉开效果,使用Flash制作卷轴展开效果
  17. 金融信创虽风正时济,应对挑战该如何乘风破浪(一)
  18. 2021年计算机考证真题二级题库
  19. 【ROS】在 Ubuntu 20.04 安装 ROS 的详细教程
  20. 移动App多渠道推广统计

热门文章

  1. Maven 极简入门
  2. 做IT这几年,我整理了这些干货想要送给你!
  3. java猜数游戏图形界面_猜数游戏java实现代码
  4. 2.6.4 Qtimer定时器介绍
  5. 手游联运SDK都有哪些功能?
  6. 外贸业务员要掌握的基本知识
  7. 超裂都市一直连不上服务器,超猎都市进不去 超猎都市打不开怎么办?[多图]
  8. 手电筒安卓_4G手机+AI智能音响+收音机+手电筒+唱戏机+插卡音箱=HT318智能版
  9. RK3568平台开发系列讲解(驱动基础篇)RK 看门狗的使用
  10. 【试用邀请】星环科技TDH社区版:让大数据分析触手可及