public void simulateLocation(Location location) { cleanupRemovedLocationListeners(); setLastKnownLocation(location.getProvider(), location); List<ListenerRegistration> providerListeners = locationListeners.get( location.getProvider()); if (providerListeners == null) return; for (ListenerRegistration listenerReg : providerListeners) { if(listenerReg.lastSeenLocation != null && location != null) { float distanceChange = distanceBetween(location, listenerReg.lastSeenLocation); boolean withinMinDistance = distanceChange < listenerReg.minDistance; boolean exceededMinTime = location.getTime() - listenerReg.lastSeenTime > listenerReg.minTime; if (withinMinDistance || !exceededMinTime) continue; } listenerReg.lastSeenLocation = copyOf(location); listenerReg.lastSeenTime = location == null ? 0 : location.getTime(); listenerReg.listener.onLocationChanged(copyOf(location)); } cleanupRemovedLocationListeners(); }
for (LocationListener locationUpdateListener : locationUpdateListeners) { if (isEnabled) { locationUpdateListener.onProviderEnabled(provider); } else { locationUpdateListener.onProviderDisabled(provider);
final LocationListener mLocationListener = new LocationListener() { @Override public void onLocationChanged(final Location location) { loclist.onLocationChanged(location); // call each listener ll.onLocationChanged(cache.getValue()); } else { if(!requested){
@Override public void onProviderDisabled( final String provider ) { MainActivity.info("provider disabled: " + provider); if ( mapLocationListener != null ) { mapLocationListener.onProviderDisabled( provider ); } }
@Override public void onProviderEnabled( final String provider ) { MainActivity.info("provider enabled: " + provider); if ( mapLocationListener != null ) { mapLocationListener.onProviderEnabled( provider ); } }
public void methodName(){ LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); android.location.LocationListener locationListener = new android.location.LocationListener() { public void onLocationChanged(Location location) { //Any method here } public void onStatusChanged (String provider, int status, Bundle extras){} public void onProviderEnabled(String provider) {} public void onProviderDisabled (String provider){} }; locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0, locationListener); }
private static long lastTime = 0; private LocationListener mLocationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { mLocationListener.onLocationChanged(lastLocation); location.setLatitude(Double.parseDouble(lat)); location.setLongitude(Double.parseDouble(lng)); mLocationListener.onLocationChanged(location); } catch (NumberFormatException e) { Log.e(TAG, "Wrong lat/lng for parsing as Double.");
context.getSystemService(android.content.Context.LOCATION_SERVICE); android.location.LocationListener locationListener = new android.location.LocationListener() {
listener.onLocationChanged(fakeLocation);
for (LocationListener locationUpdateListener : locationUpdateListeners) { if (isEnabled) { locationUpdateListener.onProviderEnabled(provider); } else { locationUpdateListener.onProviderDisabled(provider);
private void kickStardedLocationManager(){ // Acquire a reference to the system Location Manager LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates android.location.LocationListener locationListener = new android.location.LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network location provider. //MainActivity.this.makeUseOfNewLocation(location); } public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; long l = 10; float f = 100; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); //LocationManager.GPS_PROVIDER }
@Override public void onLocationChanged(Location newLocation) { if (isBetterLocation(GeoLocation.this.currentLocation, newLocation)) { GeoLocation.this.currentLocation = newLocation; for(LocationListener l:listeners){ l.onLocationChanged(newLocation); } } ... the rest of the code
for (LocationListener locationUpdateListener : locationUpdateListeners) { if (isEnabled) { locationUpdateListener.onProviderEnabled(provider); } else { locationUpdateListener.onProviderDisabled(provider);
@Override public void onLocationChanged( final Location newLocation ) { // MainActivity.info("GPS onLocationChanged: " + newLocation); updateLocationData( newLocation ); if ( mapLocationListener != null ) { mapLocationListener.onLocationChanged( newLocation ); } }
for (LocationListener locationUpdateListener : locationUpdateListeners) { if (isEnabled) { locationUpdateListener.onProviderEnabled(provider); } else { locationUpdateListener.onProviderDisabled(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); } }
for (LocationListener locationUpdateListener : locationUpdateListeners) { if (isEnabled) { locationUpdateListener.onProviderEnabled(provider); } else { locationUpdateListener.onProviderDisabled(provider);
@Override public void run() { locationManager.removeUpdates(mLocationListener); if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { Location lastNetworkLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); Location lastGpsLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if ((lastGpsLocation == null) && (lastNetworkLocation != null)) { mLocationListener.onLocationChanged(lastNetworkLocation); } else if ((lastGpsLocation != null) && (lastNetworkLocation == null)) { mLocationListener.onLocationChanged(lastGpsLocation); } else { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, mLocationListener); } } } }, LOCATION_TIMEOUT_IN_MS);
for (LocationListener locationUpdateListener : locationUpdateListeners) { if (isEnabled) { locationUpdateListener.onProviderEnabled(provider); } else { locationUpdateListener.onProviderDisabled(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); } }