Android GPS定位简单 DEMO

时间:2019-02-07 07:32:52
【文件属性】:
文件名称:Android GPS定位简单 DEMO
文件大小:73KB
文件格式:ZIP
更新时间:2019-02-07 07:32:52
Android GPS定位 使用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()); ```
【文件预览】:
.project
project.properties
proguard.cfg
src
----introduction()
--------android()
AndroidManifest.xml
res
----drawable-ldpi()
--------ic_launcher.png(2KB)
----drawable-hdpi()
--------ic_launcher.png(4KB)
----drawable-mdpi()
--------ic_launcher.png(3KB)
----layout()
--------activity_main.xml(892B)
----drawable-xhdpi()
----values()
--------strings.xml(182B)
.settings
----org.eclipse.jdt.core.prefs(177B)
assets
gen
----introduction()
--------android()
.classpath
bin
----GPSLocation.apk(15KB)
----resources.ap_(11KB)
----classes()
--------introduction()
----AndroidManifest.xml(1KB)
----dexedLibs()
----res()
--------crunch()
----GPSLocation1.apk(14KB)
----classes.dex(5KB)

网友评论

  • 骗子,根本不管用
  • 好吧 这种垃圾代码你都敢收费
  • 没得到任何定位信息
  • 用不了,还是用百度的定位demo吧
  • 适合初学者
  • 不错,简单易懂,适合初学者