<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");                    }            }

更多相关文章

  1. Android高手进阶教程(十七)之---Android中Intent传递对象的两种
  2. Android中将资源文件转为Bitmap对象
  3. 面向UDP的Android——PC双向通信(三):在Android客户端和PC服务器端
  4. Android调用WebService系列之KSoap2对象解析
  5. Android Application对象必须掌握的七点
  6. android XMl 解析神奇xstream 五: 把复杂对象转换成 xml ,并写入S
  7. Android判断网络状态是否断开+Android完全关闭应用程序+ 本文讲
  8. Android NDK 学习之传递类对象
  9. Android service的开启和绑定,以及调用service的方法

随机推荐

  1. 新手怎么画线稿?绘画线稿初学者教程
  2. Python 强大的信号库 blinker 入门教程
  3. 使用 Python 开发一个 Python 解释器
  4. 为Android应用程序读取/dev下设备而提权(
  5. 关于Android的一些设计
  6. android recovery模式及ROM制作
  7. 专项测试(三)内存泄漏调试经验分享 (一)
  8. Android(安卓)在线视频播放器(Vitamio)
  9. Android(安卓)targetSdkVersion了解一下
  10. android小白感悟:Android(安卓)Studio安装