Android GPS定位简单 DEMO

上传者: bruce_shan | 上传时间: 2021-02-26 13:57:51 | 文件大小: 73KB | 文件类型: ZIP
使用GPS 定位,首先,需要在清单文件(AndroidManifest.xml)中注册获取定位的权限: **1.获取位置管理器对象LocationManager** ``` import android.location.LocationManager; LocationManager lm; // lm =(LocationManager) this.getSystemService(Context`.LOCATION_SERVICE); // ``` **2.一般使用LocationManager的getLastKnownLocation(LocationManager.GPS_PROVIDER);方法获取Location对象** ``` String provider = LocationManager.GPS_PROVIDER;// 指定LocationManager的定位方法 Location location = locationManager.getLastKnownLocation(provider);// 调用getLastKnownLocation()方法获取当前的位置信息 ``` 不过不建议用这种方法,有几点原因: 一,在很多提供定位服务的应用程序中,不仅需要获取当前的位置信息,还需要监视位置的变化,在位置改变时调用特定的处理方法 ,其中LocationManager提供了一种便捷、高效的位置监视方法requestLocationUpdates(),可以根据位置的距离变化和时间间隔设定,产生位置改变事件的条件,这样可以避免因微小的距离变化而产生大量的位置改变事件 。 二,当你开启GPS,provider的值为GPS。这时的定位方式为GPS,由于GPS定位慢,所以它不可能立即返回你一个Location对象,所以就返回null了。 **3.推荐locationManager.requestLocationUpdates();方法** LocationManager中设定监听位置变化的代码如下: ``` lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 10,new MyLocationListener()); ```

文件下载

资源详情

[{"title":"( 32 个子文件 73KB ) Android GPS定位简单 DEMO","children":[{"title":".project <span style='color:#111;'> 847B </span>","children":null,"spread":false},{"title":"project.properties <span style='color:#111;'> 361B </span>","children":null,"spread":false},{"title":"proguard.cfg <span style='color:#111;'> 1.22KB </span>","children":null,"spread":false},{"title":"src","children":[{"title":"introduction","children":[{"title":"android","children":[{"title":"gpsLocationin","children":[{"title":"MainActivity.java <span style='color:#111;'> 2.50KB </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true}],"spread":true},{"title":"AndroidManifest.xml <span style='color:#111;'> 1.11KB </span>","children":null,"spread":false},{"title":"res","children":[{"title":"drawable-ldpi","children":[{"title":"ic_launcher.png <span style='color:#111;'> 1.68KB </span>","children":null,"spread":false}],"spread":true},{"title":"drawable-hdpi","children":[{"title":"ic_launcher.png <span style='color:#111;'> 4.05KB </span>","children":null,"spread":false}],"spread":true},{"title":"drawable-mdpi","children":[{"title":"ic_launcher.png <span style='color:#111;'> 2.51KB </span>","children":null,"spread":false}],"spread":true},{"title":"layout","children":[{"title":"activity_main.xml <span style='color:#111;'> 892B </span>","children":null,"spread":false}],"spread":true},{"title":"drawable-xhdpi","children":null,"spread":false},{"title":"values","children":[{"title":"strings.xml <span style='color:#111;'> 182B </span>","children":null,"spread":false}],"spread":true}],"spread":true},{"title":".settings","children":[{"title":"org.eclipse.jdt.core.prefs <span style='color:#111;'> 177B </span>","children":null,"spread":false}],"spread":true},{"title":"assets","children":null,"spread":false},{"title":"gen","children":[{"title":"introduction","children":[{"title":"android","children":[{"title":"gpsLocation","children":[{"title":"BuildConfig.java <span style='color:#111;'> 174B </span>","children":null,"spread":false},{"title":"R.java <span style='color:#111;'> 871B </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true}],"spread":true},{"title":".classpath <span style='color:#111;'> 475B </span>","children":null,"spread":false},{"title":"bin","children":[{"title":"GPSLocation.apk <span style='color:#111;'> 15.04KB </span>","children":null,"spread":false},{"title":"resources.ap_ <span style='color:#111;'> 10.71KB </span>","children":null,"spread":false},{"title":"classes","children":[{"title":"introduction","children":[{"title":"android","children":[{"title":"gpsLocation","children":[{"title":"R$layout.class <span style='color:#111;'> 445B </span>","children":null,"spread":false},{"title":"BuildConfig.class <span style='color:#111;'> 373B </span>","children":null,"spread":false},{"title":"R$drawable.class <span style='color:#111;'> 449B </span>","children":null,"spread":false},{"title":"R$attr.class <span style='color:#111;'> 382B </span>","children":null,"spread":false},{"title":"R$id.class <span style='color:#111;'> 488B </span>","children":null,"spread":false},{"title":"R.class <span style='color:#111;'> 629B </span>","children":null,"spread":false},{"title":"R$string.class <span style='color:#111;'> 469B </span>","children":null,"spread":false}],"spread":false},{"title":"gpsLocationin","children":[{"title":"MainActivity$MyLocationListener.class <span style='color:#111;'> 1.92KB </span>","children":null,"spread":false},{"title":"MainActivity$1.class <span style='color:#111;'> 1.16KB </span>","children":null,"spread":false},{"title":"MainActivity.class <span style='color:#111;'> 2.20KB </span>","children":null,"spread":false}],"spread":false}],"spread":false}],"spread":false}],"spread":true},{"title":"AndroidManifest.xml <span style='color:#111;'> 1.11KB </span>","children":null,"spread":false},{"title":"dexedLibs","children":null,"spread":false},{"title":"res","children":[{"title":"crunch","children":[{"title":"drawable-ldpi","children":[{"title":"ic_launcher.png <span style='color:#111;'> 1.50KB </span>","children":null,"spread":false}],"spread":false},{"title":"drawable-hdpi","children":[{"title":"ic_launcher.png <span style='color:#111;'> 3.87KB </span>","children":null,"spread":false}],"spread":false},{"title":"drawable-mdpi","children":[{"title":"ic_launcher.png <span style='color:#111;'> 2.15KB </span>","children":null,"spread":false}],"spread":false}],"spread":false}],"spread":false},{"title":"GPSLocation1.apk <span style='color:#111;'> 14.41KB </span>","children":null,"spread":false},{"title":"classes.dex <span style='color:#111;'> 5.32KB </span>","children":null,"spread":false}],"spread":true}],"spread":true}]

评论信息

  • u013447704 :
    骗子,根本不管用
    2021-03-02
  • guoyongcan :
    好吧 这种垃圾代码你都敢收费
    2017-07-10
  • qq_39000550 :
    没得到任何定位信息
    2017-06-09
  • diangongshi :
    用不了,还是用百度的定位demo吧
    2017-03-14
  • leiricong :
    适合初学者
    2016-12-10

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明