Java Code Examples for com.google.android.gms.location.LocationResult#getLocations()

The following examples show how to use com.google.android.gms.location.LocationResult#getLocations() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocationBackgroundService.java    From rn-background-location with MIT License 6 votes vote down vote up
private LocationCallback createLocationRequestCallback() {
    return new LocationCallback() {
        @Override
        public void onLocationResult(LocationResult locationResult) {
            if (locationResult == null) {
                return;
            }
            for (Location location : locationResult.getLocations()) {
                LocationCoordinates locationCoordinates = createCoordinates(location.getLatitude(), location.getLongitude());
                broadcastLocationReceived(locationCoordinates);
                mFusedLocationClient.removeLocationUpdates(mLocationCallback);
            }
        }
    };
}
 
Example 2
Source File: WearableMainActivity.java    From wear-os-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void onLocationResult(LocationResult locationResult) {
    if (locationResult == null) {
        return;
    }


    for (Location location : locationResult.getLocations()) {
        Log.d(TAG, "onLocationChanged() : " + location);


        if (mWaitingForGpsSignal) {
            mWaitingForGpsSignal = false;
            updateActivityViewsBasedOnLocationPermissions();
        }

        mSpeed = location.getSpeed() * MPH_IN_METERS_PER_SECOND;
        updateSpeedInViews();
        addLocationEntry(location.getLatitude(), location.getLongitude());
    }
}
 
Example 3
Source File: EasyWayLocation.java    From EasyWayLocation with Apache License 2.0 6 votes vote down vote up
/**
 * Starts updating the location and requesting new updates after the defined interval
 */
@SuppressLint("MissingPermission")
private void beginUpdates() {
    locationCallback = new LocationCallback(){
        @Override
        public void onLocationResult(LocationResult locationResult) {
            if (locationResult == null) {
                mListener.locationCancelled();
            }else {
                for (Location location : locationResult.getLocations()) {
                    mListener.currentLocation(location);
                }
            }

        }
    };

    fusedLocationClient.requestLocationUpdates(locationRequest,
            locationCallback,
            Looper.getMainLooper());
}
 
Example 4
Source File: LocationUpdatesBroadcastReceiver.java    From background_location_updates with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (intent != null) {
        final String action = intent.getAction();
        if (ACTION_PROCESS_LOCATION_UPDATE.equals(action)) {
            LocationResult result = LocationResult.extractResult(intent);
            if (result != null) {
                List<Location> locations = result.getLocations();
                LocationEntity[] locationEntities = new LocationEntity[locations.size()];
                for (int i = 0; i < locations.size(); i++) {
                    locationEntities[i] = LocationEntity.fromAndroidLocation(locations.get(i));
                }
                new TraceInserter(context).execute(locationEntities);
            }
        }
    }
}
 
Example 5
Source File: LocationUpdatesIntentService.java    From background-location-updates-android-o with Apache License 2.0 6 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    if (intent != null) {
        final String action = intent.getAction();
        if (ACTION_PROCESS_UPDATES.equals(action)) {
            LocationResult result = LocationResult.extractResult(intent);
            if (result != null) {
                List<Location> locations = result.getLocations();
                LocationResultHelper locationResultHelper = new LocationResultHelper(this,
                        locations);
                // Save the location data to SharedPreferences.
                locationResultHelper.saveResults();
                // Show notification with the location data.
                locationResultHelper.showNotification();
                Log.i(TAG, LocationResultHelper.getSavedLocationResult(this));
            }
        }
    }
}
 
Example 6
Source File: LocationUpdatesBroadcastReceiver.java    From background-location-updates-android-o with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (intent != null) {
        final String action = intent.getAction();
        if (ACTION_PROCESS_UPDATES.equals(action)) {
            LocationResult result = LocationResult.extractResult(intent);
            if (result != null) {
                List<Location> locations = result.getLocations();
                LocationResultHelper locationResultHelper = new LocationResultHelper(
                        context, locations);
                // Save the location data to SharedPreferences.
                locationResultHelper.saveResults();
                // Show notification with the location data.
                locationResultHelper.showNotification();
                Log.i(TAG, LocationResultHelper.getSavedLocationResult(context));
            }
        }
    }
}
 
Example 7
Source File: LocationUpdatesIntentService.java    From location-samples with Apache License 2.0 5 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    if (intent != null) {
        final String action = intent.getAction();
        if (ACTION_PROCESS_UPDATES.equals(action)) {
            LocationResult result = LocationResult.extractResult(intent);
            if (result != null) {
                List<Location> locations = result.getLocations();
                Utils.setLocationUpdatesResult(this, locations);
                Utils.sendNotification(this, Utils.getLocationResultTitle(this, locations));
                Log.i(TAG, Utils.getLocationUpdatesResult(this));
            }
        }
    }
}
 
Example 8
Source File: LocationUpdatesBroadcastReceiver.java    From location-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (intent != null) {
        final String action = intent.getAction();
        if (ACTION_PROCESS_UPDATES.equals(action)) {
            LocationResult result = LocationResult.extractResult(intent);
            if (result != null) {
                List<Location> locations = result.getLocations();
                Utils.setLocationUpdatesResult(context, locations);
                Utils.sendNotification(context, Utils.getLocationResultTitle(context, locations));
                Log.i(TAG, Utils.getLocationUpdatesResult(context));
            }
        }
    }
}
 
Example 9
Source File: CustomerMapActivity.java    From UberClone with MIT License 5 votes vote down vote up
@Override
public void onLocationResult(LocationResult locationResult) {
    for(Location location : locationResult.getLocations()){
        if(getApplicationContext()!=null){
            mLastLocation = location;

            LatLng latLng = new LatLng(location.getLatitude(),location.getLongitude());

            //mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
            //mMap.animateCamera(CameraUpdateFactory.zoomTo(11));
            if(!getDriversAroundStarted)
                getDriversAround();
        }
    }
}
 
Example 10
Source File: DriverMapActivity.java    From UberClone with MIT License 5 votes vote down vote up
@Override
public void onLocationResult(LocationResult locationResult) {
    for(Location location : locationResult.getLocations()){
        if(getApplicationContext()!=null){

            if(!customerId.equals("") && mLastLocation!=null && location != null){
                rideDistance += mLastLocation.distanceTo(location)/1000;
            }
            mLastLocation = location;


            LatLng latLng = new LatLng(location.getLatitude(),location.getLongitude());
            mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
            mMap.animateCamera(CameraUpdateFactory.zoomTo(11));

            String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
            DatabaseReference refAvailable = FirebaseDatabase.getInstance().getReference("driversAvailable");
            DatabaseReference refWorking = FirebaseDatabase.getInstance().getReference("driversWorking");
            GeoFire geoFireAvailable = new GeoFire(refAvailable);
            GeoFire geoFireWorking = new GeoFire(refWorking);

            switch (customerId){
                case "":
                    geoFireWorking.removeLocation(userId);
                    geoFireAvailable.setLocation(userId, new GeoLocation(location.getLatitude(), location.getLongitude()));
                    break;

                default:
                    geoFireAvailable.removeLocation(userId);
                    geoFireWorking.setLocation(userId, new GeoLocation(location.getLatitude(), location.getLongitude()));
                    break;
            }
        }
    }
}
 
Example 11
Source File: GoogleLocationEngineImpl.java    From mapbox-events-android with MIT License 5 votes vote down vote up
@Override
public void onLocationResult(LocationResult locationResult) {
  super.onLocationResult(locationResult);
  List<Location> locations = locationResult.getLocations();
  if (!locations.isEmpty()) {
    callback.onSuccess(LocationEngineResult.create(locations));
  } else {
    callback.onFailure(new Exception("Unavailable location"));
  }
}
 
Example 12
Source File: LocationAwareService.java    From LocationAware with Apache License 2.0 5 votes vote down vote up
@Override public void onLocationResult(LocationResult locationResult) {
  for (Location location : locationResult.getLocations()) {
    Log.i("Debug ", "On Location Available " + location.toString());
    currentLocation = location;
    matchForCheckPoints();
  }
}
 
Example 13
Source File: MyLocationUpdateReceiver.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
  if (LocationResult.hasResult(intent)) {
    LocationResult locationResult = LocationResult.extractResult(intent);
    for (Location location : locationResult.getLocations()) {
      // TODO React to newly received location.
    }
  }
}
 
Example 14
Source File: HomeFragment.java    From SEAL-Demo with MIT License 5 votes vote down vote up
@Override
public void onLocationResult(LocationResult locationResult) {
    List<Location> locationList = locationResult.getLocations();
    if (!locationList.isEmpty()) {
        Location location = locationList.get(locationList.size() - 1);
        Log.i(TAG, "Location: " + location.getLatitude() + " " + location.getLongitude());
        //Place current location marker
        LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
        //move map camera
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, MAP_ZOOM));
    }
}
 
Example 15
Source File: RunService.java    From SEAL-Demo with MIT License 5 votes vote down vote up
@Override
public void onLocationResult(LocationResult locationResult) {
    List<Location> locationList = locationResult.getLocations();
    if (locationList.size() > 0) {
        if (currentLocation == null) {
            currentLocation = locationList.get(locationList.size() - 1);
        } else {
            mLastLocation = currentLocation;
            currentLocation = locationList.get(locationList.size() - 1);
            if (mLastLocation.distanceTo(currentLocation) > MIN_DISTANCE_UPDATE && currentLocation.getAccuracy() < MIN_ACCURACY_GPS)
                distance += mLastLocation.distanceTo(currentLocation) * KILOMETER_METER_CONVERSION_RATE; // return distance in meter and then it is converted in kilometers
        }
    }
}
 
Example 16
Source File: LocationActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 4 votes vote down vote up
@Override
public void onLocationResult(LocationResult locationResult) {
  for (Location location : locationResult.getLocations()) {
    // TODO React to newly received locations.
  }
}
 
Example 17
Source File: BackgroundLocationBroadcastReceiver.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (intent != null) {
        final String action = intent.getAction();
        if (ACTION_PROCESS_UPDATES.equals(action)) {
            LocationResult result = LocationResult.extractResult(intent);
            Location lastLocation = null;
            if (result != null) {
                List<Location> locations = result.getLocations();
                for (Location loc : locations){
                    lastLocation = loc;
                }
            } else {
                return;
            }

            if (lastLocation == null) {
                return;
            }
            String dataString = intent.getDataString();
            if (dataString == null) {
                return;
            }
            String[] params = dataString.split("[?]");
            if (params.length < 2) {
                return;
            }
            Class locationListenerClass;
            try {
                locationListenerClass = Class.forName(params[1]);
            } catch (Throwable t) {
                return;
            }
          
            
            boolean shouldStopWhenDone = false;
            if (!Display.isInitialized()) {
                shouldStopWhenDone = true;
                AndroidImplementation.startContext(context);
            }

            try {
                //the 2nd parameter is the class name we need to create
                LocationListener l = (LocationListener)locationListenerClass.newInstance();
                l.locationUpdated(AndroidLocationManager.convert(lastLocation));
            } catch (Throwable e) {
                Log.e("Codename One", "background location error", e);
            } finally {
                if (shouldStopWhenDone) {
                    AndroidImplementation.stopContext(context);
                }
            }
        }
    }
}