【发布时间】:2015-03-16 22:09:08
【问题描述】:
我的任务是确定用户位置。我可以在 Application 类中创建 LocationListener。或者我可以使用服务。
LocationManager locationManager=(LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener=new LocationListener(){
public void onLocationChanged( Location location){
dive.setLongitude(location.getLongitude());
dive.setLatitude(location.getLatitude());
mapHelper.setMapPosition(dive.getLatitude(),dive.getLongitude());
}
public void onStatusChanged( String provider, int status, Bundle extras){
}
public void onProviderEnabled( String provider){
}
public void onProviderDisabled( String provider){
}};
locationManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER,0,0,locationListener);
locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER,0,0,locationListener);
我需要用什么来完成这项任务?服务或应用程序类?服务的优点和缺点是什么?应用类的优缺点是什么?
【问题讨论】: