Code examples for Finding current location

Codota analyzed 7,668,838 open source code samples to find the most common, credible and clear examples.
You can now enable Codota on your own code to easily search and navigate your Java codebase.
	        locationManager = (LocationManager) myAndroidContext 
	                .getSystemService(Context.LOCATION_SERVICE); 
 
	        // getting GPS status 
	        isGPSEnabled = locationManager 
	                .isProviderEnabled(LocationManager.GPS_PROVIDER); 
 
	        // getting network status 
	        isNetworkEnabled = locationManager 
	                .isProviderEnabled(LocationManager.NETWORK_PROVIDER); 
 
	        if (!isGPSEnabled && !isNetworkEnabled) { 
	            // no network provider is enabled 
	        } else { 
	            this.canGetLocation = true; 
	            if (isNetworkEnabled) { 
	                locationManager.requestLocationUpdates( 
	                        LocationManager.NETWORK_PROVIDER, 
	                        MIN_TIME_BW_UPDATES, 
	                        MIN_DISTANCE_CHANGE_FOR_UPDATES, this); 

10
CodeRank
		cLoc = mLocMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
	} 
	 
	public Location getLocation() 
	{ 
		cLoc = mLocMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
		return cLoc; 
	} 
 
	public void onProviderDisabled(String provider) { 
		// TODO Auto-generated method stub 
		Log.d(LOG_TAG, "The provider " + provider + " is disabled"); 
	} 
 
 
	public void onProviderEnabled(String provider) { 
		// TODO Auto-generated method stub 
		Log.d(LOG_TAG, "The provider "+ provider + " is enabled"); 
	} 
 
Full Snippet Info
10
CodeRank
		cLoc = mLocMan.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
	} 
	 
	public Location getLocation() 
	{ 
		cLoc = mLocMan.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
		return cLoc; 
	} 
	 
	public void onProviderDisabled(String provider) { 
		// TODO Auto-generated method stub 
		Log.d(LOG_TAG, "The provider " + provider + " is disabled"); 
		owner.fail(); 
	} 
 
	public void onProviderEnabled(String provider) { 
		// TODO Auto-generated method stub 
		Log.d(LOG_TAG, "The provider "+ provider + " is enabled"); 
	} 
 
Full Snippet Info
10
CodeRank
	 
	 
	@Override 
	public void async(Context context){ 
		lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);		 
		gpsEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); 
		networkEnabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER); 
		work(); 
	} 
	 
	public LocationAjaxCallback timeout(long timeout){ 
		this.timeout = timeout; 
		return this; 
	} 
	 
	public LocationAjaxCallback accuracy(float accuracy){ 
		this.accuracy = accuracy; 
		return this; 
	} 
	 

9
CodeRank
			locationManager = (LocationManager) mContext 
					.getSystemService(LOCATION_SERVICE); 
 
			// getting GPS status 
			isGPSEnabled = locationManager 
					.isProviderEnabled(LocationManager.GPS_PROVIDER); 
 
			// getting network status 
			isNetworkEnabled = locationManager 
					.isProviderEnabled(LocationManager.NETWORK_PROVIDER); 
 
			if (!isGPSEnabled && !isNetworkEnabled) { 
				// no network provider is enabled 
			} else { 
				this.canGetLocation = true; 
				if (isNetworkEnabled) { 
					locationManager.requestLocationUpdates( 
							LocationManager.NETWORK_PROVIDER, 
							MIN_TIME_BW_UPDATES, 
							MIN_DISTANCE_CHANGE_FOR_UPDATES, this); 

8
CodeRank
     * @param myLocationFoundListener the callback 
     */ 
    public void requestLocationUpdates(MyLocationFoundListener myLocationFoundListener) { 
        mMyLocationFoundListener = myLocationFoundListener; 
 
        if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { 
            mGpsLocationListener = new MyLocationListener(); 
            mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 
                    0, 0, mGpsLocationListener); 
        } 
 
        if (mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { 
            mNetworkLocationListener = new MyLocationListener(); 
            mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 
                    0, 0, mNetworkLocationListener); 
        } 
 
        if (mNetworkLocationListener != null || mGpsLocationListener != null) { 
            mLocationRequestTimeOut.start(); 
        } else { 

8
CodeRank
			locationManager = (LocationManager) mContext 
					.getSystemService(LOCATION_SERVICE); 
 
			// getting GPS status 
			isGPSEnabled = locationManager 
					.isProviderEnabled(LocationManager.GPS_PROVIDER); 
 
			// getting network status 
			isNetworkEnabled = locationManager 
					.isProviderEnabled(LocationManager.NETWORK_PROVIDER); 
 
			if (!isGPSEnabled && !isNetworkEnabled) { 
				// no network provider is enabled 
			} else { 
				this.canGetLocation = true; 
				if (isNetworkEnabled) { 
					locationManager.requestLocationUpdates( 
							LocationManager.NETWORK_PROVIDER, 
							MIN_TIME_BW_UPDATES, 
							MIN_DISTANCE_CHANGE_FOR_UPDATES, this); 

8
CodeRank
	try 
	{ 
	    locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE); 
 
	    // getting GPS status 
	    isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); 
 
	    // getting network status 
	    isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); 
 
	    if (!isGPSEnabled && !isNetworkEnabled) 
	    { 
		// no network provider is enabled 
	    } 
	    else 
	    { 
		this.canGetLocation = true; 
		if (isNetworkEnabled) 
		{ 
		    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this); 

7
CodeRank
	} 
 
	@Override 
	public void onResume() { 
		locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); 
		locationManager.removeUpdates(this); 
		locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this ); 
		locationManager.addGpsStatusListener(this); 
		 
		currentLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
		if (currentLocation == null) { 
			currentLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
		} 
	} 
 
	@Override 
	public void onLocationChanged(Location location) { 
		Log.i(TAG, "new location: "+location); 
		currentLocation = location; 
		map.redraw(); 
Full Snippet Info
7
CodeRank
	} 
	 
	public Location getLocation(){ 
		 
		locationManager = (LocationManager)mContext.getSystemService(LOCATION_SERVICE); 
		gpsStatus = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); 
		networkStatus = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); 
			 
		if (!gpsStatus && !networkStatus) { 
            locationStatus = false; 
        } else { 
         
        	Criteria criteria = new Criteria(); 
        	criteria.setAccuracy(Criteria.ACCURACY_FINE); 
            provider = locationManager.getBestProvider(criteria, true); 
           
             
            locationManager.requestLocationUpdates(provider, 60*100000, 0, this); 
            location = (locationManager.getLastKnownLocation(provider)); 
            if (location != null) { 

7
CodeRank