Android实现实现Service获取当前位置获取当前位置(GPS+基站基站)的方法的方法
主要介绍了Android实现Service获取当前位置(GPS+基站)的方法,较为详细的分析了Service基于GPS位置的技巧,具
有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了Android实现Service获取当前位置(GPS+基站)的方法。分享给大家供大家参考。具体如下:
需求详情:需求详情:
1)、Service中每隔1秒执行一次定位操作(GPS+基站)
2)、定位的结果实时显示在界面上(要求得到经度、纬度)
技术支持:技术支持:
1)、获取经纬度
通过GPS+基站获取经纬度,先通过GPS来获取,如果为空改用基站进行获取–>GPS+基站(基站获取支持联通、电信、移动)。
2)、实时获取经纬度
为了达到实时获取经纬度,需在后台启动获取经纬度的Service,然后把经纬度数据通过广播发送出去,在需要的地方进行广播注
册(比如在Activity中注册广播,显示在界面中)–>涉及到Service+BroadcastReceiver+Activity+Thread等知识点。
备注:备注:本文注重实践,如有看不懂的,先去巩固下知识点,可以去看看前面相关的几篇文章。
1、CellInfo实体类–>基站信息
package com.ljq.activity;
/**
* 基站信息
*
* @author jiqinlin
*
*/
public class CellInfo {
/** 基站id,用来找到基站的位置 */
private int cellId;
/** 移动国家码,共3位,中国为460,即imsi前3位 */
private String mobileCountryCode="460";
/** 移动网络码,共2位,在中国,移动的代码为00和02,联通的代码为01,电信的代码为03,即imsi第4~5位 */
private String mobileNetworkCode="0";
/** 地区区域码 */
private int locationAreaCode;
/** 信号类型[选 gsm|cdma|wcdma] */
private String radioType="";
public CellInfo() {
}
public int getCellId() {
return cellId;
}
public void setCellId(int cellId) {
this.cellId = cellId;
}
public String getMobileCountryCode() {
return mobileCountryCode;
}
public void setMobileCountryCode(String mobileCountryCode) {
this.mobileCountryCode = mobileCountryCode;
}
public String getMobileNetworkCode() {
return mobileNetworkCode;
}
public void setMobileNetworkCode(String mobileNetworkCode) {
this.mobileNetworkCode = mobileNetworkCode;
}
public int getLocationAreaCode() {
return locationAreaCode;
}
public void setLocationAreaCode(int locationAreaCode) {
this.locationAreaCode = locationAreaCode;
}
public String getRadioType() {
return radioType;
}
public void setRadioType(String radioType) {
this.radioType = radioType;
}
}
2、Gps类–>Gps封装类,用来获取经纬度
评论0