<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(安卓)8、Android(安卓)9获取手机序列号的兼容写法
  2. Android(安卓)学习笔记--android――Activity学习
  3. android之蓝牙操作(二)
  4. Android(安卓)studio 3.1.3 无法获取pom文件
  5. View常见XML属性及相关方法
  6. Android(安卓)获取手机唯一标识(仅限IMEI)
  7. Android存储权限
  8. Android(安卓)控件之DatePicker,TimePicker,Calender
  9. ANDROID获取设备ID、型号及其它信息

随机推荐

  1. Android编程示例之——人像检测
  2. Android新控件MotionLayout介绍(二)
  3. Android事件分发之前做了啥?
  4. Genymotion Android模拟器下载和找不到模
  5. Android(安卓)APP 进入后台开启手势密码
  6. Android Studio中minSdkVersion、targetS
  7. Android Studio升级提示 Connection fail
  8. Android中两种使用Animation的方法
  9. Android 中 Activity 的4种启动模式
  10. 详解Android aidl的使用方法