public class GPSInfoService {
private static GPSInfoService mInstance;
private LocationManager locationManager;//定位服务
private GPSInfoService(Context context) {
// TODO Auto-generated constructor stub
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
}
public static GPSInfoService getInstance(Context context){
if(mInstance == null){
mInstance = new GPSInfoService(context);
}
return mInstance;
}
//注册定位监听
public void registenerLocationChangeListener(){
//得到所有的定位服务
// List<String> providers = locationManager.getAllProviders();
// for(String provider:providers){
// Log.i("i", provider);
// }
//查询条件
Criteria criteria = new Criteria();
//定位的精准度
criteria.setAccuracy(Criteria.ACCURACY_FINE);
//海拔信息是否关注
criteria.setAltitudeRequired(false);
//对周围的事情是否进行关心
criteria.setBearingRequired(false);
//是否支持收费的查询
criteria.setCostAllowed(true);
//是否耗电
criteria.setPowerRequirement(Criteria.POWER_LOW);
//对速度是否关注
criteria.setSpeedRequired(false);
//得到最好的定位方式
String provider = locationManager.getBestProvider(criteria, true);
//注册监听
locationManager.requestLocationUpdates(provider, 60000, 0, getListener());
}
//取消监听
public void unRegisterLocationChangeListener(){
locationManager.removeUpdates(getListener());
}
private MyLocationListener listener;
//得到定位的监听器
private MyLocationListener getListener(){
if(listener == null){
listener = new MyLocationListener();
}
return listener;
}
//得到上个地理位置
public String getLastLocation(){
return sp.getString("last_location", "");
}
private final class MyLocationListener implements LocationListener{
//位置的改变
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
double latitude = location.getLatitude();//维度
double longitude = location.getLongitude();//经度
String last_location = "jingdu: " + longitude + ",weidu:" + latitude;
Editor editor = sp.edit();
editor.putString("last_location", last_location);
editor.commit();
}
//gps卫星有一个没有找到
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
//某个设置被打开
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
//某个设置被关闭
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有