android之location01
2014-04-25 22:51
246 查看
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container" android:layout_width="fill_parent" android:layout_height="fill_parent" tools:context="com.example.mars_3200_location01.MainActivity" tools:ignore="MergeRootFrame" android:orientation="vertical"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="hello"/> <Button android:id="@+id/locationButtonId" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="绑定监听器"/> </LinearLayout>
private class ButtonListener implements OnClickListener { @Override public void onClick(View v) { //绑定位置对象,得到LocationManager对象 LocationManager locationManager=(LocationManager)MainActivity.this.getSystemService(Context.LOCATION_SERVICE); //定义当前所使用的Location Provider locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new TestLocationListener()); } } class TestLocationListener implements LocationListener { @Override public void onLocationChanged(Location location) { System.out.println("onLocationChanged"); System.out.println(location.getLongitude());//获取经度 System.out.println(location.getLatitude());//获取纬度 } @Override public void onStatusChanged(String provider, int status, Bundle extras) { System.out.println("onStatusChanged"); } @Override public void onProviderEnabled(String provider) { System.out.println("onProviderEnabled"); } @Override public void onProviderDisabled(String provider) { System.out.println("onProviderDisabled"); } }
相关文章推荐
- Android Wi-Fi Display(Miracast)介绍
- Android中Activity四种启动模式和taskAffinity属性详解
- android adb 命令发送 keyevent
- android的ListView的适配器的使用
- Android端的微博项目
- 将HTML5封装成android应用APK文件若干方法
- Android_Servlet验证的简单登录程序
- 【Android类型SDK测试(一)】认识Android类型的 SDK
- 华为Android手机打开Log, 显示日志
- Java4Android(第41~43集)类集框架
- android 输入法的打开和关闭
- android自动更新程序,安装完以后就什么都没有了,没有出现安装成功的界面的问题
- 完美解决android显示gif
- android menu菜单的动态隐藏
- Android系统SVC命令教程
- Android系统中Activity的生命周期
- android 获取控件大小和设置调整控件的位置XY
- Android开发之Json-构建Json文本
- android从完全不懂菜鸟开始到有经验的coder之路
- 得到SD卡的文件目录