Android GPS获取当前位置信息

该博客介绍了一个在Android中使用单例模式获取GPS当前位置信息的实现方法。通过`LocationManager`服务,选择最佳定位提供者,并注册`LocationListener`来监听位置变化,将经纬度信息保存在`SharedPreferences`中。
摘要由CSDN通过智能技术生成
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
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值