Code example for LocationManager: Finding current location

Methods: getLastKnownLocationisProviderEnabledrequestLocationUpdates

0
			 
			//set up location manager 
			locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE);
			 
			// getting GPS status 
			boolean isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
 
			// getting network status 
			boolean isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
			 
			 
			if(isNetworkEnabled){	
				locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,MIN_TIME_BW_UPDATES,MIN_DISTANCE_CHANGE_FOR_UPDATES, this);		
				if (locationManager != null) {
						location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
							if (location != null) {
								latitude = location.getLatitude();
								longitude = location.getLongitude();
							} 
				} 
			} 
			 
			// if GPS Enabled get lat/long using GPS Services 
 
			if(isGPSEnabled){
				locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,MIN_TIME_BW_UPDATES,MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
							 
				if (locationManager != null) {
								 
					location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
					if (location != null) {
						latitude = location.getLatitude();
						longitude = location.getLongitude();
					} 
				} 
Stop searching for code, let great code find you!  Add Codota to your java IDE