下面是手机基站定位代码:

public class CellIDInfo {public int cellId;public String mobileCountryCode;public String mobileNetworkCode;public int locationAreaCode;public String radioType;public CellIDInfo(){}
}

public class WifiInfo {public String mac;public WifiInfo(){}
}

import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.telephony.NeighboringCellInfo;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.telephony.cdma.CdmaCellLocation;
import android.telephony.gsm.GsmCellLocation;
public class CellIDInfoManager {private TelephonyManager manager;private PhoneStateListener listener;private GsmCellLocation gsm;private CdmaCellLocation cdma;int lac;String current_ci,mcc, mnc;public CellIDInfoManager(){}public ArrayList<CellIDInfo> getCellIDInfo(Context context){manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);listener = new PhoneStateListener();manager.listen(listener, 0);ArrayList<CellIDInfo> CellID = new ArrayList<CellIDInfo>();CellIDInfo currentCell = new CellIDInfo();int type = manager.getNetworkType();if (type == TelephonyManager.NETWORK_TYPE_GPRS || type ==TelephonyManager.NETWORK_TYPE_EDGE|| type ==TelephonyManager.NETWORK_TYPE_HSDPA) {gsm = ((GsmCellLocation) manager.getCellLocation());if (gsm == null) return null;lac  = gsm.getLac();mcc = manager.getNetworkOperator().substring(0, 3);mnc = manager.getNetworkOperator().substring(3, 5);currentCell.cellId = gsm.getCid();currentCell.mobileCountryCode = mcc;currentCell.mobileNetworkCode = mnc;currentCell.locationAreaCode = lac;currentCell.radioType = "gsm";CellID.add(currentCell);List<NeighboringCellInfo> list = manager.getNeighboringCellInfo();int size = list.size();for (int i = 0; i < size; i++) {CellIDInfo info = new CellIDInfo();info.cellId = list.get(i).getCid();info.mobileCountryCode = mcc;info.mobileCountryCode = mnc;info.locationAreaCode = lac;CellID.add(info);}return CellID;} else if (type == TelephonyManager.NETWORK_TYPE_CDMA || type ==TelephonyManager.NETWORK_TYPE_1xRTT) {cdma = ((CdmaCellLocation) manager.getCellLocation());if (cdma == null) return null;if ("460".equals(manager.getSimOperator().substring(0, 3))) return null;}return null;}
}

import java.util.ArrayList;
import android.content.Context;
import android.net.wifi.WifiManager;
public class WifiInfoManager {WifiManager wm;public WifiInfoManager(){}public ArrayList getWifiInfo(Context context){ArrayList<WifiInfo> wifi = new ArrayList();wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);WifiInfo info = new WifiInfo();info.mac = wm.getConnectionInfo().getBSSID();wifi.add(info);return wifi;}
}

private Location callGear(ArrayList<WifiInfo> wifi,ArrayList<CellIDInfo> cellID) {if (cellID == null) return null;DefaultHttpClient client = new DefaultHttpClient();HttpPost post = new HttpPost("http://www.google.com/loc/json");JSONObject holder = new JSONObject();try {holder.put("version", "1.1.0");holder.put("host", "maps.google.com");holder.put("home_mobile_country_code", cellID.get(0).mobileCountryCode);holder.put("home_mobile_network_code", cellID.get(0).mobileNetworkCode);holder.put("radio_type", cellID.get(0).radioType);holder.put("request_address", true);if ("460".equals(cellID.get(0).mobileCountryCode)) holder.put("address_language", "zh_CN");elseholder.put("address_language", "en_US");JSONObject data,current_data;JSONArray array = new JSONArray();current_data = new JSONObject();current_data.put("cell_id", cellID.get(0).cellId);current_data.put("mobile_country_code", cellID.get(0).mobileCountryCode);current_data.put("mobile_network_code", cellID.get(0).mobileNetworkCode);current_data.put("age", 0);array.put(current_data);if (cellID.size() > 2) {for (int i = 1; i < cellID.size(); i++) {data = new JSONObject();data.put("cell_id", cellID.get(i).cellId);data.put("location_area_code", cellID.get(0).locationAreaCode);data.put("mobile_country_code", cellID.get(0).mobileCountryCode);data.put("mobile_network_code", cellID.get(0).mobileNetworkCode);data.put("age", 0);array.put(data);}}holder.put("cell_towers", array);if (wifi.get(0).mac != null) {data = new JSONObject();data.put("mac_address", wifi.get(0).mac);data.put("signal_strength", 8);data.put("age", 0);array = new JSONArray();array.put(data);holder.put("wifi_towers", array);}StringEntity se = new StringEntity(holder.toString());Log.e("Location send", holder.toString());post.setEntity(se);HttpResponse resp = client.execute(post);HttpEntity entity = resp.getEntity();BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));StringBuffer sb = new StringBuffer();String result = br.readLine();while (result != null) {Log.e("Locaiton reseive", result);sb.append(result);result = br.readLine();}data = new JSONObject(sb.toString());data = (JSONObject) data.get("location");Location loc = new 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(AppUtil.getUTCTime());return loc;} catch (JSONException e) {return null;} catch (UnsupportedEncodingException e) {e.printStackTrace();} catch (ClientProtocolException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}return null;}

转载于:https://www.cnblogs.com/topwang-com/archive/2012/12/18/2823023.html

手机基站定位(安卓手机定位源码)相关推荐

  1. java编程手机gps定位_GPS 获取Gps定位信息的Android源码实例,通过这个JAVA 目,你可能学会GPS在 手机 238万源代码下载- www.pudn.com...

    文件名称: GPS下载 收藏√  [ 5  4  3  2  1 ] 开发工具: Java 文件大小: 59 KB 上传时间: 2013-04-08 下载次数: 22 详细说明:获取Gps定位信息的A ...

  2. 手机直播开发,直播程序源码,直播源码分享经验

    手机直播开发,直播程序源码,直播系统开发,直播源码 2016-2017年是网络直播元年,发展了酝酿了10来年的网络直播市场终于在这一年开始喷发,手机直播开发更成为炙手可热的市场新宠儿,而如何进行手机直 ...

  3. 在线教育丨在线课堂丨知识付费系统丨自适应手机版虚拟资源下载php源码

    源码简介: 这是一款知识付费系统,后台可上传本地视频,批量上传视频连接,视频后台可设计权限观看,免费试看时间时长,会员等级观看,付费观 看等功能,也带软件app权限下载,帮助知识教育和软件推广企业提升 ...

  4. fastslam matlab,fastslam 快速定位和构图的源码,一个简单的例子,3D建模,可以用作学习智能机器人自主移动 matlab 272万源代码下载- www.pudn.com...

    文件名称: fastslam下载  收藏√  [ 5  4  3  2  1 ] 开发工具: matlab 文件大小: 31 KB 上传时间: 2015-03-19 下载次数: 22 详细说明:快速定 ...

  5. 微信小程序:升级版手机检测微信工具小程序源码

    这是一款升级版检测工具 自动检测手机真伪,序列号等等 另外还可以给手机检测各项功能是否正常 由于能检测的项目太多,所以大家到时候自行研究吧 小编就不多做介绍 另外支持多做流量主模式,比如激励视频,ba ...

  6. 手zhuan手机软件app下载排行网站源码(需要自取)

    demo软件园每日更新资源,请看到最后就能获取你想要的: 1.嵌入式Qt实战教程 PDF 高清版 嵌入式Qt实战教程 是配合Qt GUI程序设计的指导教材,独立于任何Qt编程教科书.主要内容有常用GU ...

  7. 一套手机点餐收银系统源码,系统功能完善、页面美观,开源分享!

    淘源码:国内知名的源码免费下载平台 需要源码学习可私信我获取. 一套手机点餐收银系统源码,系统功能完善.页面美观,非常适合有编程基础的进行学习.本套点餐系统解决了餐饮复杂繁琐的点餐程序,实现从点餐到后 ...

  8. 嵌入式毕设分享 GSM手机短信收发系统(源码+论文)

    文章目录 1 简介 1 硬件设计 1.1 TC35i模块 1.2 单片机硬件链接 2 软件设计 2.1 软件流程图 3 关键代码 4 最后 1 简介 Hi,大家好,这里是丹成学长,今天向大家介绍一个 ...

  9. stm32毕设分享 GSM手机短信收发系统(源码+论文)

    文章目录 1 简介 1 硬件设计 1.1 TC35i模块 1.2 单片机硬件链接 2 软件设计 2.1 软件流程图 3 关键代码 4 最后 1 简介 Hi,大家好,这里是丹成学长,今天向大家介绍一个 ...

  10. 手机QQ侧滑菜单_从源码上一步步解析效果的实现

    本文思想来自洪洋大哥,本来写的原创的,有些朋友看到标题后认为是照搬翔哥的例子,仔细看看,会有不同,不过其中的主要思想还是翔哥的,滑动方面的算法还真是有些区别的,看完了就知道不一样,而且我这人比较啰嗦, ...

最新文章

  1. 返回倒数第 k 个节点
  2. python编程视频-【科研资源03】最全Python编程全套系统视频学习教程
  3. 【系统平台】大四区部署
  4. 请说明一下http和https的区别
  5. 手把手教你搭建Mac环境微信小程序的本地测试服务器
  6. P3358 最长k可重区间集问题(网络流:串联思想)
  7. spring安全性_具有PreAuthorize的Spring方法安全性
  8. 为MongoDB定制Spring Social Connect框架
  9. printf(“%f“,a/b)
  10. 了解SQL Server数据库静态数据及其如何适合数据库生命周期管理
  11. 这个Wi-Fi安全漏洞偷跑了24年,可能危及全球所有设备!
  12. oracle11 dataguard,探索Oracle之11g DataGuard
  13. 如何让pm2支持es6
  14. 华为手机连电脑当摄像头用_怎么用华为手机当电脑摄像头
  15. Mac视频下载转换器MovieSherlock使用教程
  16. 百度账号 不用手机号注册
  17. 微信公众号开发(四)自定义菜单
  18. InstallShield Slient Uninstall
  19. 微服务系统架构设计系列 - RateLimiter - 1. 限流器简介与一般算法
  20. 7-20 打印九九口诀表(分数 15)

热门文章

  1. java原始模型模式_java设计模式--原始模型模式
  2. java简单的面试题目_简单的面试题目,大跌眼镜的结果
  3. 943602cs 蓝牙驱动 win10_英特尔升级WiFi 和蓝牙驱动,Win10 更新5月版稳了
  4. 获取当天0点时间_什么是股市T+0?该如何做T?
  5. python datetime datetime_Python datetime.tzinfo方法代碼示例
  6. oracle10.2 迁移,实战:Oracle10.2.0.4异机迁移并升级到Oracle 11.2.0.4
  7. 11年瑞纳手动挡值多少钱_三分钟让你知道手中的松石值多少钱
  8. 实战 PK!RTX2080Ti 对比 GTX1080Ti 的 CIFAR100 混合精度训练
  9. FastDFS安装、配置、部署(一)
  10. SSO 认证机制对比