【原创】CDMA基站定位获取经纬度

一介布衣萧萧 2011-01-10 11:26:00
【原创】CDMA基站定位获取经纬度
本贴最初原创地址:
http://www.cmd100.com/bbs/forum-viewthread-tid-5325-fromuid-9.html


这几天在做基站定位,发觉CDMA的基站定位在网上资料很少。经过漫长的摸索,其中的小小收获给大家分享一下!
这个是CDMA中国电信的基站定位获取经纬度的源码及测试截图!在模拟器中用似乎不行,模拟器的网络不是CDMA的。有知道的请指点指点!

主要代码:

public void onClick(View v) {
// TODO Auto-generated method stub
tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
//int type = tm.getNetworkType();
//if (type ==TelephonyManager.NETWORK_TYPE_CDMA) {
location = (CdmaCellLocation) tm.getCellLocation();
if(location == null)
return;
int sid = location.getSystemId();//系统标识 mobileNetworkCode
int bid = location.getBaseStationId();//基站小区号 cellId
int nid = location.getNetworkId();//网络标识 locationAreaCode

Log.i(\"sid:\", \"\" + sid);
Log.i(\"bid:\", \"\" + bid);
Log.i(\"nid:\", \"\" + nid);
ArrayList<CellIDInfo> CellID = new ArrayList<CellIDInfo>();
CellIDInfo info = new CellIDInfo();
info.cellId = bid;
info.locationAreaCode = nid;
info.mobileNetworkCode = String.valueOf(sid);
info.mobileCountryCode = tm.getNetworkOperator().substring(0, 3);
info.mobileCountryCode = tm.getNetworkOperator().substring(3, 5);
info.radioType = \"cdma\";
CellID.add(info);
Log.d(\"cellId:\", \"\" + info.cellId);
Log.d(\"locationAreaCode:\", \"\" + info.locationAreaCode);
Log.d(\"mobileNetworkCode:\", info.mobileNetworkCode);
Log.d(\"mobileCountryCode:\", info.mobileCountryCode);
Location loc = callGear(CellID);

if (loc !=null)
mTextView.setText(\"纬度:\" + loc.getLatitude() + \"\\n经度:\" + loc.getLongitude());
//}// end if
}// end onclick


调用google gears的方法,该方法调用gears来获取经纬度 代码:

//调用google gears的方法,该方法调用gears来获取经纬度
private Location callGear(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\");
else
holder.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(\"location_area_code\", cellID.get(0).locationAreaCode);
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);
current_data.put(\"signal_strength\", -60);
current_data.put(\"timing_advance\", 5555);
array.put(current_data);

holder.put(\"cell_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());
Log.d(\"-\", 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( System.currentTimeMillis());//AppUtil.getUTCTime());
return loc;
} catch (JSONException e) {
e.printStackTrace();
return null;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Log.d(\"-\", \"null 1\");
return null;
}


在弄这个的时候不要忘了加权限噢!

<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"></uses-permission>
<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"></uses-permission>
<uses-permission android:name=\"android.permission.INTERNET\"></uses-permission>


程序只是测试用,尚不完善!希望这个东东对需要的朋友有用!有什么不对的地方请大家指点指点。
若需要看源码可在本站中搜索资源,名字与帖名一样。或者到最初的原创地址去下载。
...全文
7197 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
minigpsnet 2013-04-26
  • 打赏
  • 举报
回复
http://www.minigps.net/map.html 提供cdma定位接口
ABCpenglujiahao 2013-02-06
  • 打赏
  • 举报
回复
除了手机,还有其它基站定位设备吗?
B439984445 2011-11-13
  • 打赏
  • 举报
回复
CdmaCellLocation这个类是从哪个版本开始有的,我的1.6的sdk只有GsmCellLocation类
liqiupost 2011-08-04
  • 打赏
  • 举报
回复
感谢分享心得
wang1588143 2011-07-13
  • 打赏
  • 举报
回复
一定要想楼主表示一下感谢啊
fallenmaple21 2011-05-11
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 dengta_snowwhite 的回复:]

有人用过CdmaCellLocation 的 getBaseStationLatitude () 和 getBaseStationLongitude ()获取基站的经纬度吗?
一定需要调用google gears方法来获取经纬度吗?
我这边用getBaseStationLatitude ()得到的都是Integer.MAX_VALUE,是否跟具体的机型也有关系
[/Quote]参考一下这个链接
http://blog.csdn.net/dengta_snowwhite/archive/2011/04/02/6297204.aspx
jesperzx 2011-04-30
  • 打赏
  • 举报
回复
我已经用楼主的方法成功获取了cdma基站了,并且写了一个在pc上的查询程序,欢迎提意见阿
http://www.mymobiletrack.com/mobile/space.php?uid=2445&do=blog&id=584

谢谢lz
shenzhentom 2011-03-31
  • 打赏
  • 举报
回复
这种定位方式的精度 高不高 ?

能不能达到传统 GPS 定位的精度?
dengta_snowwhite 2011-03-30
  • 打赏
  • 举报
回复
我用楼主的方法测试怎么报错呢?

CdmaCellLocation 的 getBaseStationLatitude () 和 getBaseStationLongitude ()获取的信息在不同的地方不一样,但是搞不懂得到的数据要怎样转成真正的经纬度
譬如获得的getBaseStationLatitude () 值有: 430241 430222等
dengta_snowwhite 2011-03-30
  • 打赏
  • 举报
回复
有人用过CdmaCellLocation 的 getBaseStationLatitude () 和 getBaseStationLongitude ()获取基站的经纬度吗?
一定需要调用google gears方法来获取经纬度吗?
我这边用getBaseStationLatitude ()得到的都是Integer.MAX_VALUE,是否跟具体的机型也有关系
jesperzx 2011-01-14
  • 打赏
  • 举报
回复
windows mobile 有没有办法实现阿
一介布衣萧萧 2011-01-12
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 drsmart 的回复:]

在android平台上,cellid已经由ril提供了,获取时java层无需判断平台,当然cdma机型,在后来sdk单独分离了,你的错误,是因为当前cellid值模拟器无法模拟
[/Quote]

多谢啦!俺是新手,还真不知道有这个事!学习了。
DrSmart 2011-01-11
  • 打赏
  • 举报
回复
在android平台上,cellid已经由ril提供了,获取时java层无需判断平台,当然cdma机型,在后来sdk单独分离了,你的错误,是因为当前cellid值模拟器无法模拟
ameyume 2011-01-11
  • 打赏
  • 举报
回复
帮顶,膜拜LZ的无私奉献精神。
WCDMA,TD的是不是也可以实现啊?
DrSmart 2011-01-11
  • 打赏
  • 举报
回复
模拟器无法模拟cellid,gps坐标可以用kml模拟
Smile__LV 2011-01-11
  • 打赏
  • 举报
回复
4楼说的错误是个什么意思?
c8051f330 2011-01-10
  • 打赏
  • 举报
回复
不错,可能会用得上,谢谢了,到用上了一起讨论

80,348

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧