Code example for LocationManager: Getting continuous location updates

Methods: addGpsStatusListenerremoveUpdatesrequestLocationUpdates

0
		mMinUpdateDistance = minDistance;
		mUsingGpsLocation = false;
		mUsingCoarseLocation = false;
		switchToCoarseLocationUpdates(); 
		if (mLocationManager != null) {
	        mLocationManager.addGpsStatusListener(mGpsStatusListener);
		} 
	} 
	 
	 
	public void swithToGpsLocationUpdates() { 
		if (mUsingGpsLocation) {
			return; 
		} 
		if (mLocationManager != null) {
			if (D) { Log.d(TAG, "Using GPS location updates. minTime=" + mMinUpdateTime + ", minDistance=" + mMinUpdateDistance); }
			// clean up first 
			mLocationManager.removeUpdates(mCoarseLocationProviderListener);
			mLocationManager.removeUpdates(mGpsLocationProviderListener);
			mUsingGpsLocation = false;
	        mUsingCoarseLocation = false;
			 
			// set new listeners 
			if (mGpsLocationProvider != null) {
				mLocationManager.requestLocationUpdates(mGpsLocationProvider, mMinUpdateTime, mMinUpdateDistance, mGpsLocationProviderListener);
		        mUsingGpsLocation = true;
			} 
			 
	        // update location info 
	        gotoLastKnownLocation(); 
		} 
	} 
	 
	 
	public void switchToCoarseLocationUpdates() { 
		if (mUsingCoarseLocation) {
			return; 
		} 
		if (mLocationManager != null) {
			if (D) { Log.d(TAG, "Using coarse location updates and monitoring GPS status. minTime=" + mMinUpdateTime + ", minDistance=" + mMinUpdateDistance); }
			// clean up first 
			mLocationManager.removeUpdates(mCoarseLocationProviderListener);
			mLocationManager.removeUpdates(mGpsLocationProviderListener);
	        mUsingCoarseLocation = false;
	        mUsingGpsLocation = false;
 
	        // set new listeners 
			if (mCoarseLocationProvider != null) {
				mLocationManager.requestLocationUpdates(mCoarseLocationProvider, mMinUpdateTime, mMinUpdateDistance, mCoarseLocationProviderListener);
		        mUsingCoarseLocation = true;
			} 
			 
			if (mGpsLocationProvider != null) {
				mLocationManager.requestLocationUpdates(mGpsLocationProvider, mMinUpdateTime, mMinUpdateDistance, mGpsLocationProviderListener);
			} 
			 
	        // update location info 
	        gotoLastKnownLocation(); 
		} 
Experience pair programming with AI  Get Codota for Java