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(); }
listener.onLocationChanged(fakeLocation);
@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
@Override public void onLocationChanged( final Location newLocation ) { // MainActivity.info("GPS onLocationChanged: " + newLocation); updateLocationData( newLocation ); if ( mapLocationListener != null ) { mapLocationListener.onLocationChanged( newLocation ); } }
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); } }
@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);
@Override public void run() { locationManager.removeUpdates(mLocationListener); if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { Location lastLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (lastLocation != null) { mLocationListener.onLocationChanged(lastLocation); } else { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mLocationListener); } } } }, LOCATION_TIMEOUT_IN_MS);
@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); } }
locationListener.onLocationChanged(location); } else locationListener.onLocationChanged(location); Button button = (Button) findViewById(R.id.cmdButton); button.setText("Get me home");
loclist.onLocationChanged(location); // call each listener ll.onLocationChanged(cache.getValue()); } else { if(!requested){
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.");
Location lastGpsLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if ((lastGpsLocation == null) && (lastNetworkLocation != null)) { locationListener.onLocationChanged(lastNetworkLocation); } else if ((lastGpsLocation != null) && (lastNetworkLocation == null)) { locationListener.onLocationChanged(lastGpsLocation); } else { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
.show(); else { gpsListener.onLocationChanged(mlocManager .getLastKnownLocation(LocationManager.GPS_PROVIDER));
listener.onLocationChanged(recentLoc);
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(); }
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(); }
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(); }
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(); }
if ((lastGpsLocation == null) && (lastNetworkLocation != null)) { locationsDbHelper.updateLocationSource(currentLocation.getId(), getString(R.string.location_weather_update_status_location_from_network)); locationListener.onLocationChanged(lastNetworkLocation); } else if ((lastGpsLocation != null) && (lastNetworkLocation == null)) { locationsDbHelper.updateLocationSource(currentLocation.getId(), getString(R.string.location_weather_update_status_location_from_gps)); locationListener.onLocationChanged(lastGpsLocation); } else if (AppPreference.isGpsEnabledByPreferences(getBaseContext())){ locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);