/**
*
获取基站信息
*
@return
* @throws
Exception
*/
public SCell getCellInfo() throws Exception
{
SCell cell
= new SCell();
TelephonyManager
mTelNet = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
GsmCellLocation
location = (GsmCellLocation) mTelNet.getCellLocation();
if
(location == null)
throw new
Exception("基站信息为空");
String
operator = mTelNet.getNetworkOperator();
int mcc =
Integer.parseInt(operator.substring(0, 3));
int mnc =
Integer.parseInt(operator.substring(3));
int cid =
location.getCid();
int lac =
location.getLac();
cell.MCC =
mcc;
cell.MNC =
mnc;
cell.LAC =
lac;
cell.CID =
cid;
return
cell;
}
/**
*
通过基站信息获取经纬度
* @param
cell
*
@return
* @throws
Exception
*/
private SItude getItude(SCell cell) throws Exception
{
SItude
itude = new SItude();
HttpClient
client = new DefaultHttpClient();
try
{
JSONObject
holder = new JSONObject();
holder.put("version",
"1.1.0");
holder.put("host",
"maps.google.com");
holder.put("address_language",
"zh_CN");
holder.put("request_address",
true);
holder.put("radio_type",
"gsm");
holder.put("carrier",
"HTC");
JSONObject
tower = new JSONObject();
tower.put("mobile_country_code",
cell.MCC);
tower.put("mobile_network_code",
cell.MNC);
tower.put("cell_id",
cell.CID);
tower.put("location_area_code",
cell.LAC);
JSONArray
towerarray = new JSONArray();
towerarray.put(tower);
holder.put("cell_towers",
towerarray);
StringEntity
query = new StringEntity(holder.toString());
post.setEntity(query);
HttpResponse
response = client.execute(post);
HttpEntity
entity = response.getEntity();
BufferedReader
buffReader = new BufferedReader(
new
InputStreamReader(entity.getContent()));
StringBuffer
strBuff = new StringBuffer();
String
result = null;
while
((result = buffReader.readLine()) != null) {
strBuff.append(result);
}
JSONObject
json = new JSONObject(strBuff.toString());
JSONObject
subjosn = new JSONObject(json.getString("location"));
itude.latitude
= subjosn.getString("latitude");
itude.longitude
= subjosn.getString("longitude");
Log.i("Itude",
itude.latitude + itude.longitude);
} catch
(Exception e) {
Log.e(e.getMessage(),
e.toString());
throw new
Exception("" + e.getMessage());
} finally
{
post.abort();
client =
null;
}
return
itude;
}
/**
*
通过经纬度到Google map上获取地理位置
* @param
itude
*
@return
* @throws
Exception
*/
private String getLocation(SItude itude) throws
Exception {
String
resultString = "";
String
urlString = String.format(
itude.latitude,
itude.longitude);
Log.i("URL",
urlString);
HttpClient
client = new DefaultHttpClient();
HttpGet get
= new HttpGet(urlString);
try
{
HttpResponse
response = client.execute(get);
HttpEntity
entity = response.getEntity();
BufferedReader
buffReader = new BufferedReader(
new
InputStreamReader(entity.getContent()));
StringBuffer
strBuff = new StringBuffer();
String
result = null;
while
((result = buffReader.readLine()) != null) {
strBuff.append(result);
}
resultString
= strBuff.toString();
if
(resultString != null && resultString.length() > 0)
{
JSONObject
jsonobject = new JSONObject(resultString);
JSONArray
jsonArray = new JSONArray(jsonobject.get("Placemark")
.toString());
resultString
= "";
for (int i
= 0; i < jsonArray.length(); i++) {
resultString
= jsonArray.getJSONObject(i).getString(
"address");
}
}
} catch
(Exception e) {
throw new
Exception("sd:" + e.getMessage());
} finally
{
get.abort();
client =
null;
}
return
resultString;
}
public class SCell {
public int
MCC;
public int
MNC;
public int
LAC;
public int
CID;
}
public class SItude {
public
String latitude;
public
String longitude;
}
分享到:
相关推荐
获取基站信息相关的内容,包括的想尽的信息内容,很清晰,很好用
NULL 博文链接:https://104zz.iteye.com/blog/1680860
源码 博文链接:https://104zz.iteye.com/blog/1680811
GPS基站与地理因素
android定位之基站定位,获取不到GPS信号定位时解决定位
android基站定位
百度地图 wifi定位 获取地理位置 GPS 基站
android GPS和基站定位程序及源码.rar 实现基站定位,以及WIFI定位,以及GPS定位,参考使用。
本文实例讲述了Android实现Service获取当前位置(GPS+基站)的方法。分享给大家供大家参考。具体如下: 需求详情: 1)、Service中每隔1秒执行一次定位操作(GPS+基站) 2)、定位的结果实时显示在界面上(要求得到经度、...
Android的基站、WIFI、GPS定位三点定位结合
通过Web页面获取基站位置Web端源码 首先要清楚一点的是,每一个基站都能够通过请求http://www.google.com/loc/json获取到一个经纬度。如果用户能够在短时间内获取到较多的基站信息,比如4个或5个,可以通过这几个...
android平台上实现3G基站定位功能,完整源码,多次测试。
通过Web页面获取基站位置Web端源码 首先要清楚一点的是,每一个基站都能够通过请求http://www.google.com/loc/json获取到一个经纬度。如果用户能够在短时间内获取到较多的基站信息,比如4个或5个,可以通过这几个...
Android 基站定位例子
这是android实现基站定位的实现步骤及源代码。
这是超葛格刚刚封装好的定理信息定位代码,专门用于wifi定位、基站定位。本人是技术爱好者,如有同道中人,请联系我。本人QQ:82076424;本人邮箱mejg@163.com
Android studio 请使用真机调试,测试地点,最好在室外,基站定位好像不会实时定位,GPS可以2秒刷新一次,前提是可以接收到GPS信号
android 基站定位程序 目前仅支持联通、移动通信商
Android系统手机基站信息库开发与设计.doc