Android 使用LocationLstenser获取位置信息

第一步:

  注册一个LocationLstenser:

this.locationManager=(LocationManager)this.getSystemService(Context.LOCATION_SERVICE); this.locationProvider=this.locationManager.getProvider(LocationManager.GPS_PROVIDER); if(locationManager!=null) { this.locationManager.requestLocationUpdates(locationProvider.getName(),3000,1,this.myLocationLstenser); } else { Log.e("error","a error"); }       

第二部:实现myLocationLstenser

LocationListener myLocationLstenser=new LocationListener()

{ 
@Override public void onLocationChanged(Location arg0)

{ Log.i("position","position has changed!");

latitude=arg0.getLatitude();

double longitude=arg0.getLongitude();

double altitude=arg0.getAltitude();

float bearing=arg0.getBearing();         

Log.i("position", "a new position");

@Override public void onProviderDisabled(String arg0) { // TODO Auto-generated method stub } 
@Override public void onProviderEnabled(String arg0) { // TODO Auto-generated method stub } 
@Override public void onStatusChanged(String arg0, int arg1, Bundle arg2) { // TODO Auto-generated method stub }

};

andoid 中获取位置信息的方式友好多种,这种一般使用在后台服务程序中。使用android的,注意了,谷歌偷偷的记录了你们每天的行踪,你们在使用网络的时候,所有的,URL都是经过谷歌搜索的,搜索的时候顺手拿走了你的位置信息,不信打看你的手机的浏览器  打开 google.com.hk看看有没有  周边这一项,这就是google的基于位置的服务(LBS)

原文地址:https://www.cnblogs.com/changefuture/p/2300969.html