GPS和Network定位各有优劣:
GPS定位精确,但耗电耗时;Network则相反,低能耗且定位迅速,但定位误差较大。
非导航类的,一般用Network定位已经足够了。
开启定位服务:
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
设置一个监听:
LocationListener listener = new LocationListener() {
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method