android定位GPS定位 代码实现
package com.lx.util; |
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;/* * 要求是单态的 ,只允许存在一个实例. * 获取手机的gps信息 */public class GPSInfoService { private Context context; private LocationManager manager; SharedPreferences sp ; //1. 私有化构造方法 private GPSInfoService(Context context){ this.context= context; manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); sp = context.getSharedPreferences("config", Context.MODE_PRIVATE); } private static GPSInfoService mGPSService; public synchronized static GPSInfoService getInstance(Context context){ if(mGPSService==null) mGPSService = new GPSInfoService(context); return mGPSService; } public void registerLocationUpdates(){ //当前你的手机 所支持的定位方式获取出来 //有多种定位方式 gps network ,基站, passive //可以根据定位的条件 ,获取 一个最好的定位方式 Criteria criteria = new Criteria(); // 设置定位的精度 criteria.setAccuracy(Criteria.ACCURACY_COARSE); //获取大体的位置 criteria.setAltitudeRequired(false); // 海拔信息 criteria.setCostAllowed(true); //允许产生费用 criteria.setPowerRequirement(Criteria.POWER_LOW); //低功耗 //获取一个最符合查询条件的位置提供者 String provider =manager.getBestProvider(criteria, true); // 注册 位置改变的监听器 manager.requestLocationUpdates(provider, 60000, 0, getLinster()); } public void cancleLocationUpdates(){ manager.removeUpdates(getLinster()); } private static MyGPSLinster myGPSLinser; private MyGPSLinster getLinster(){ if(myGPSLinser==null) myGPSLinser = new MyGPSLinster(); return myGPSLinser; } /** * 获取手机的最后一次位置 * @return */ public String getLastPosition(){ return sp.getString("lastlocation", ""); } private class MyGPSLinster implements LocationListener{ // 用户位置改变的时候 的回调方法 public void onLocationChanged(Location location) { // TODO Auto-generated method stub //location //获取到用户的纬度 double latitude= location.getLatitude(); double longitude = location.getLongitude(); String locationstr = "jing du "+ longitude + " weidu :"+latitude; Editor editor = sp.edit(); editor.putString("lastlocation", locationstr); editor.commit(); } // 状态改变 public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } //gps ,打开 public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } //关闭 public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } }}android定位GPS定位 代码实现的更多相关文章
- [置顶]
xamarin android使用gps定位获取经纬度
看了文章你会得出以下几个结论 1.android定位主要有四种方式GPS,Network(wifi定位.基站定位),AGPS定位 2.绝大部分android国产手机使用network进行定位是没有作用 ...
- Android中GPS定位的简单应用
在Android中通过GPS获得当前位置,首先要获得一个LocationManager实例,通过该实例的getLastKnownLocation()方法获得第一个的位置,该方法的说明如下: void ...
- android 获取GPS定位
AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xm ...
- 【Android】GPS定位基本原理浅析
位置服务已经成为越来越热的一门技术,也将成为以后所有移动设备(智能手机.掌上电脑等)的标配.而定位导航技术中,目前精度最高.应用最广泛的,自然非GPS莫属了.网络上介绍GPS原理的专业资料很多,而本文 ...
- Android开发——GPS定位
1.LocationManager LocationManager系统服务是位置服务的核心组件,它提供了一系列方法来处理与位置相关的问题. 与LocationManager相关的两个知识点: 1.1 ...
- Android之GPS定位详解
一.LocationManager LocationMangager,位置管理器.要想操作定位相关设备,必须先定义个LocationManager.我们可以通过如下代码创建LocationManger ...
- Arcgis API for Android之GPS定位
欢迎大家增加Arcgis API for Android的QQ交流群:337469080 先说说写这篇文章的原因吧,在群内讨论的过程中,有人提到了定位的问题,刚好,自己曾经在做相关工作的时候做过相关的 ...
- Arcgis For Android之GPS定位实现
翻开曾经做的东西,看了看,非常多从逻辑上比較乱,对之做了改动,完毕后实现的效果为: MapActivity源码例如以下: package com.lzugis.map; import java.io. ...
- Gps定位和wifi定位和基站定位的比较
现在手机定位的方式是:Gps定位,wifi定位,基站定位 Gps定位的前提,手机开启Gps定位模块,在室外,定位的精度一般是几米的范围 wifi定位的前提,手机要开启wifi,连不连上wifi热点都可 ...
随机推荐
- Dx unsupported class file version 52.0
最近用ADT时遇到这个bug,折腾了好几天. 报错信息: Dx unsupported class file version 52.0 Conversion to Dalvik format fail ...
- MVC学习(四)几种分页的实现(2)
在第一种分页方式中,仅仅实现了分页,但并未有体现出MVC的优势,没有体现出泛型编程思想,尤其在数据量很大的时候,分页十分缓慢,除此之外,还没有实现很好的封装,不是一个通用方法. 因此,我希望只要传入数 ...
- boxes
boxes [英][bɒksɪz][美][bɑ:ksɪz] n.盒( box的名词复数 ); 一盒; 电视; 小亭; v.把…装入盒[箱,匣]中( box的第三人称单数 ); 拳击; 以上结果来自 ...
- ABAP 加锁与解锁
维护一个旧程序,直接用UPDATE更新数据库透明表,现要求加上正在操作提示,以免数据出错. 1.先找到PA30多人修改时对应的锁对象. 2.在UPDATE前加锁,调用函数. CALL FUNCTION ...
- UWP深入学习四:动画及图像
Storyboarded animations Key-frame animations and easing function animations 缓动函数 缓动函数支持你将自定义数学公式应用到动 ...
- Android之Fragment学习总结(1)
对于Fragment的学习: 近日初步学习了Fragment这以特殊的组件,其依托与一个Activity,与Activity的生命周期息息相关,为其设置的视图只有当其关联到一个Activity才会起效 ...
- spring随想
//不定时持续更新 1.拦截器通过配置文件,在某方法前后添加一些处理,如权限判断等,减少了改方法需要处理的事,是其更专注,由配置文件来设定责任链,更灵活,而且责任链能够复用(一方面是这样能由sprin ...
- 利用SET STATISTICS IO和SET STATISTICS TIME 优化SQL Server查询性能
首先需要说明的是这篇文章的内容并不是如何调节SQL Server查询性能的(有关这方面的内容能写一本书),而是如何在SQL Server查询性能的调节中利用SET STATISTICS IO和SET ...
- objective-c 创建工程/编译/运行程序
// First program example #import <Foundation/Foundation.h> int main (int argc, const char * ar ...
- T4模板之初体验(语法)
一.什么是T4模板 T4是Text Template Transformation Toolkit(文本模板转换工具包)的四个英文首字母的简称.是微软提供的一种代码生成引擎. 在ADO.NET实体数据 ...