package com.example.gpstest;
import org.apache.http.util.LangUtils;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.text.TextUtils;
/**
* 保证这个类只存在一个实例
* @author zehua
*
*/
public class GPSInfoProvider {
LocationManager manager;
private static GPSInfoProvider mGPSInfoProvider; //单例
private static Context context; //单例
private static MyLoactionListener listener; //单例
//1.私有化构造方法
private GPSInfoProvider(){};
//2. 提供一个静态的方法 可以返回他的一个实例
public static synchronized GPSInfoProvider getInstance(Context context){
if(mGPSInfoProvider==null){
synchronized (GPSInfoProvider.class) {
if(mGPSInfoProvider == null){
mGPSInfoProvider = new
Android GPS获取当前位置信息
最新推荐文章于 2024-07-10 02:10:53 发布
该博客介绍了一个在Android中使用单例模式获取GPS当前位置信息的实现方法。通过`LocationManager`服务,选择最佳定位提供者,并注册`LocationListener`来监听位置变化,将经纬度信息保存在`SharedPreferences`中。
摘要由CSDN通过智能技术生成