step1:声明权限

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

 


step2:获取LocationManager对象

LocationManager locationManager = (LocationManager)LocationTest.this.getSystemService(Context.LOCATION_SERVICE);


step3:选择LocationProvider,绑定LocationListener对象

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 00new MyLocationListener());

 


附:MyLocationListener

    private class MyLocationListener implements LocationListener{

        @Override
        
public void onLocationChanged(Location location) {
            
// TODO Auto-generated method stub
            System.out.println(location.getLatitude());
            System.out.println(location.getLongitude());
        }

        @Override
        
public void onProviderDisabled(String provider) {
            
// TODO Auto-generated method stub
            
        }

        @Override
        
public void onProviderEnabled(String provider) {
            
// TODO Auto-generated method stub
            
        }

        @Override
        
public void onStatusChanged(String provider, int status, Bundle extras) {
            
// TODO Auto-generated method stub
            
        }
        
    }

 








posted on 2011-09-25 21:28 Ying-er 阅读(461) 评论(0)  编辑  收藏 所属分类: AndroidGIS/GPS

只有注册用户登录后才能发表评论。


网站导航: