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热点都可 ...
随机推荐
- Selenium2+python自动化4-Pycharm使用
前言 在写脚本之前,先要找个顺手的写脚本工具.python是一门解释性编程语言,所以一般把写python的工具叫解释器.写python脚本的工具很多,小编这里就不一一列举的,只要自己用着顺手就可以的, ...
- ADT bundle和Eclipse和Android Studio有什么区别?安卓开发该用哪个?
这三个版本的出现有一定的历史的原因:1.最开始只有eclipse+独立的adt一种开发环境,但是由于eclipe作为一种通用的ide,带来的问题太多,经常出现eclipse的版本不兼容adt的情况,或 ...
- Spark Streaming
Spark Streaming Spark Streaming 是Spark为了用户实现流式计算的模型. 数据源包括Kafka,Flume,HDFS等. DStream 离散化流(discretize ...
- dropbear
生成ssh连接所需要的公钥,如下: /usr/bin/dropbearkey -t dss -f /etc/dropbear/dropbear_dss_host_key (dss加密,长度默认 ...
- 第七次课:ssh的集成(SpringMV+Spring+Hibernate)
第一部分:程序结构 第二部分:配置 1.配置web.xml文件,启动spring和springMVC: 1)配置启动spring: <context-param> <param-na ...
- oracle 游标使用大全
转:http://www.cnblogs.com/fjfzhkb/archive/2007/09/12/891031.html oracle的游标和例子! 游标-----内存中的一块区域,存放的是se ...
- C# 基础(4)
Ref 按地址传递,引用传递:即可以往外返值,也可以对内传值. Out是用于传出值, Ref是双向的,即可以传入,也可以传出. 在传参过程中,如果参数有out,那么改变方法中参数的值,调用者方法中变量 ...
- NSA,放开那头魔兽!
面对NSA的觊觎,玩<魔兽世界>的男生们现在恐怕要护好自己的菊花了. 据新浪科技报道,亡命天涯的斯诺登还在持续爆料,最近的爆料和游戏有关: NSA和英国政府通信总署(简称“GCHQ ...
- module中build.gradle文件参数含义
主要是module的build.gradle,截图如下: 01行:apply plugin: 'com.android.application' 表示该module是这个应用程序的module ...
- Android Studio安装genymotion模拟器
1.Genymotion的安装: Genymotion无疑是目前最快最好用的模拟器.官网下载地址:https://www.genymotion.com/ 先注册,然后下载,安装VirtualBox最简 ...