Android GPS GPSBasics project hacking
2015-11-01 21:14
543 查看
一、参考源码:
GPS Basic Example - Android Example
http://androidexample.com/GPS_Basic__-__Android_Example/index.php?view=article_discription&aid=68&aaid=93
二、Permission:
三、Example:
GPS Basic Example - Android Example
http://androidexample.com/GPS_Basic__-__Android_Example/index.php?view=article_discription&aid=68&aaid=93
二、Permission:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.INTERNET" />
三、Example:
package com.example.gpsbasics; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.util.Log; import android.widget.Toast; import android.app.Activity; import android.content.Context; public class MainActivity extends Activity implements LocationListener { private LocationManager locationManager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); /********** get Gps location service LocationManager object ***********/ /********** 获取GPS服务管理对象 ************/ locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); /* Parameters : First(provider) : the name of the provider with which to register : 注册的名字 Second(minTime) : the minimum time interval for notifications, in milliseconds. This field is only used as a hint to conserve power, and actual time between location updates may be greater or lesser than this value. : 最小通知时间间隔,以毫秒为单位。此字段仅作为节省电力方式,并且位置更新之间的实际时间可以比该值更大或更小。 Third(minDistance) : the minimum distance interval for notifications, in meters : 最小间隔通知,以毫秒为单位 Fourth(listener) : a {#link LocationListener} whose onLocationChanged(Location) method will be called for each location update : 每个位置更新时谁的onLocationChanged (位置)方法将被调用 */ locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, // 3 sec 10, this); /********* After registration onLocationChanged method called periodically after each 3 sec ***********/ } /************* Called after each 3 sec **********/ @Override public void onLocationChanged(Location location) { // location.getLatitude(): 纬度 // location.getLongitude(): 维度 String str = "Latitude: "+location.getLatitude()+" \nLongitude: "+location.getLongitude(); Toast.makeText(getBaseContext(), str, Toast.LENGTH_LONG).show(); Log.e("GPSBasics", "onLocationChanged."); } @Override public void onProviderDisabled(String provider) { /******** Called when User off Gps *********/ Toast.makeText(getBaseContext(), "Gps turned off ", Toast.LENGTH_LONG).show(); } @Override public void onProviderEnabled(String provider) { /******** Called when User on Gps *********/ Toast.makeText(getBaseContext(), "Gps turned on ", Toast.LENGTH_LONG).show(); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } }
相关文章推荐
- 如何解决Android studio已分享到github的项目但是git->commit directory提交不上去
- android 73 下载图片
- Android,Java延迟两秒执行
- Android之ListView的优化
- android 实现自动换行的流布局
- 视频框架 Vitamio 使用教程+部分心得 (四) 滑动控制声音和亮度+android 4.4.X 以上时全屏播放
- Android轻量级ORM框架ActiveAndroid入门教程(转)
- android 读取联系人实例
- 观察者模式(Observer)在Android中的应用:
- android自定义控件(理论知识学习 +自定义属性的讲解)
- Android Debug Bridge(adb)
- Xamarin.Android支付宝SDK Demo
- Android中使用ShareSDK实现分享
- android 中 sqlite sql语句 参数 分析
- Android视频播放框架——封装FFMPEG的Vitamio
- android自定义带有布局视图的对话框
- android 72 确定取消对话框,单选对话框,多选对话框
- Android开发Toast样式总结
- android 调试常用命令
- Android消息处理机制--Looper,Handler,Message