LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); double longitude = location.getLongitude(); double latitude = location.getLatitude();
Location location = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if(location != null && location.getTime() > Calendar.getInstance().getTimeInMillis() - 2 * 60 * 1000) { mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); if (location != null) { Log.v("Location Changed", location.getLatitude() + " and " + location.getLongitude()); mLocationManager.removeUpdates(this);
lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); try{gps_enabled=lm.isProviderEnabled(LocationManager.GPS_PROVIDER);}catch(Exception ex){} try{network_enabled=lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);}catch(Exception ex){} lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListenerGps); if(network_enabled) lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListenerNetwork); timer1=new Timer(); timer1.schedule(new GetLastLocation(), 20000); timer1.cancel(); locationResult.gotLocation(location); lm.removeUpdates(this); lm.removeUpdates(locationListenerNetwork); timer1.cancel(); locationResult.gotLocation(location); lm.removeUpdates(this); lm.removeUpdates(locationListenerGps); gps_loc=lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); if(network_enabled) net_loc=lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
private void _getLocation() { // Get the location manager LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); Criteria criteria = new Criteria(); String bestProvider = locationManager.getBestProvider(criteria, false); Location location = locationManager.getLastKnownLocation(bestProvider); LocationListener loc_listener = new LocationListener() { public void onLocationChanged(Location l) {} public void onProviderEnabled(String p) {} public void onProviderDisabled(String p) {} public void onStatusChanged(String p, int status, Bundle extras) {} }; locationManager .requestLocationUpdates(bestProvider, 0, 0, loc_listener); location = locationManager.getLastKnownLocation(bestProvider); try { lat = location.getLatitude(); lon = location.getLongitude(); } catch (NullPointerException e) { lat = -1.0; lon = -1.0; } }
try { locationManager = (LocationManager) context .getSystemService(context.LOCATION_SERVICE); .isProviderEnabled(LocationManager.GPS_PROVIDER); System.out.println("gps band chhe" + isGPSEnabled); .isProviderEnabled(LocationManager.NETWORK_PROVIDER); .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); .getLastKnownLocation(LocationManager.GPS_PROVIDER);
void addLocationListener() { // Note: Use the Fused Location Provider from Google Play Services instead. // https://developers.google.com/android/reference/com/google/android/gms/location/FusedLocationProviderApi mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mListener); Log.d("BoundLocationMgr", "Listener added"); // Force an update with the last location, if available. Location lastLocation = mLocationManager.getLastKnownLocation( LocationManager.GPS_PROVIDER); if (lastLocation != null) { mListener.onLocationChanged(lastLocation); } }
this.isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); this.isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this); if (locationManager != null) { location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); updateCoordinates(); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this); location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); updateCoordinates();
.getSystemService(Context.LOCATION_SERVICE); try { if (locationManager.isProviderEnabled(provider)) { location = locationManager.getLastKnownLocation(provider);
super.onCreate(); LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); sendBroadcastMessage(locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME, MIN_DISTANCE, new LocationListener() { @Override
@Override public void run() { mLocationManager.removeUpdates(locationListenerGps); mLocationManager.removeUpdates(locationListenerNetwork); Location net_loc = null, gps_loc = null; if (mGpsEnabled) gps_loc = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (mNetworkEnabled) net_loc = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); //if there are both values use the latest one if (gps_loc != null && net_loc != null){ if (gps_loc.getTime() > net_loc.getTime()) mLocationResult.gotLocation(gps_loc); else mLocationResult.gotLocation(net_loc); return; } if (gps_loc != null) { mLocationResult.gotLocation(gps_loc); return; } if (net_loc != null) { mLocationResult.gotLocation(net_loc); return; } mLocationResult.gotLocation(null); } }
try { locationManager = (LocationManager) mContext .getSystemService(LOCATION_SERVICE); .isProviderEnabled(LocationManager.GPS_PROVIDER); .isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (locationManager != null) { location = locationManager .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (location != null) { latitude = location.getLatitude(); locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES, if (locationManager != null) { location = locationManager .getLastKnownLocation(LocationManager.GPS_PROVIDER); if (location != null) { latitude = location.getLatitude(); locationManager.removeUpdates(GPSTracker.this);
LocationManager locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1000L,500.0f, locationListener); Location location = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); double latitude=0; double longitude=0; latitude = location.getLatitude(); longitude = location.getLongitude();
try { locationManager = (LocationManager) context .getSystemService(context.LOCATION_SERVICE); .isProviderEnabled(LocationManager.GPS_PROVIDER); System.out.println("gps band chhe" + isGPSEnabled); .isProviderEnabled(LocationManager.NETWORK_PROVIDER); .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); .getLastKnownLocation(LocationManager.GPS_PROVIDER);
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME) void addLocationListener() { // Note: Use the Fused Location Provider from Google Play Services instead. // https://developers.google.com/android/reference/com/google/android/gms/location/FusedLocationProviderApi mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mListener); Log.d("BoundLocationMgr", "Listener added"); // Force an update with the last location, if available. Location lastLocation = mLocationManager.getLastKnownLocation( LocationManager.GPS_PROVIDER); if (lastLocation != null) { mListener.onLocationChanged(lastLocation); } }
Location location = locationManager.getLastKnownLocation(provider); protected void onResume() { super.onResume(); locationManager.requestLocationUpdates(provider, 400, 1, this); protected void onPause() { super.onPause(); locationManager.removeUpdates(this);
String bestProvider = locationManager.getBestProvider(criteria, false); if (bestProvider != null && checkForLocationPermissionsAndRequest()) { location = locationManager.getLastKnownLocation(bestProvider); if (locationManager.isProviderEnabled(bestProvider) && locationListener == null) { locationListener = new LocationListener() { @Override locationManager.requestLocationUpdates(bestProvider, 1, LOCATION_CHANGE_THRESHOLD, locationListener, Looper.getMainLooper());
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false)); if (location != null) { map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 13)); CameraPosition cameraPosition = new CameraPosition.Builder() .target(new LatLng(location.getLatitude(), location.getLongitude())) // Sets the center of the map to location user .zoom(17) // Sets the zoom .bearing(90) // Sets the orientation of the camera to east .tilt(40) // Sets the tilt of the camera to 30 degrees .build(); // Creates a CameraPosition from the builder map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); }
.getSystemService(Context.LOCATION_SERVICE); gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER); gps_loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (network_enabled) net_loc = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
/** * @return the best location fetched */ @SuppressLint("MissingPermission") public Location getDeviceLocation() { if (bestLocation == null) { if (psLabPermission.checkPermissions((Activity) context, PSLabPermission.MAP_PERMISSION)) { locationManager.requestLocationUpdates(provider, UPDATE_INTERVAL_IN_MILLISECONDS, MIN_DISTANCE_CHANGE_FOR_UPDATES, locationListener); if (locationReady) { return locationManager.getLastKnownLocation(provider); } else { return dummyLocation(); } } else { return dummyLocation(); } } else { return bestLocation; } }
locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE); isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); locationManager.requestLocationUpdates( provider_info, MIN_TIME_BW_UPDATES, location = locationManager.getLastKnownLocation(provider_info); updateGPSCoordinates(); locationManager.removeUpdates(GPSTracker.this);