首页 > 移动平台 > 详细

android之location01

时间:2014-04-30 05:33:09      阅读:414      评论:0      收藏:0      [点我收藏+]

 

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

 

bubuko.com,布布扣
<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>
bubuko.com,布布扣

 

bubuko.com,布布扣
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");
            
        }
        
    }
bubuko.com,布布扣

 

android之location01,布布扣,bubuko.com

android之location01

原文:http://www.cnblogs.com/zhuawang/p/3690335.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!