Search in sources :

Example 1 with LocationRequest

use of com.google.android.gms.location.LocationRequest in project RSAndroidApp by RailwayStations.

the class MapsActivity method createLocationRequest.

/**
     * Sets up the location request. Android has two location request settings:
     * {@code ACCESS_COARSE_LOCATION} and {@code ACCESS_FINE_LOCATION}. These settings control
     * the accuracy of the current location. This sample uses ACCESS_FINE_LOCATION, as defined in
     * the AndroidManifest.xml.
     * <p/>
     * When the ACCESS_FINE_LOCATION setting is specified, combined with a fast update
     * interval (5 seconds), the Fused Location Provider API returns location updates that are
     * accurate to within a few feet.
     * <p/>
     * These settings are appropriate for mapping applications that show real-time location
     * updates.
     */
protected void createLocationRequest() {
    mLocationRequest = new LocationRequest();
    // Sets the desired interval for active location updates. This interval is
    // inexact. You may not receive updates at all if no location sources are available, or
    // you may receive them slower than requested. You may also receive updates faster than
    // requested if other applications are requesting location at a faster interval.
    mLocationRequest.setInterval(LOCATION_REQUEST_INTERVAL_MILLIS);
    // Sets the fastest rate for active location updates. This interval is exact, and your
    // application will never receive updates faster than this value.
    mLocationRequest.setFastestInterval(LOCATION_REQUEST_INTERVAL_MILLIS);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
Also used : LocationRequest(com.google.android.gms.location.LocationRequest)

Example 2 with LocationRequest

use of com.google.android.gms.location.LocationRequest in project RSAndroidApp by RailwayStations.

the class NearbyNotificationService method startLocationUpdates.

private void startLocationUpdates() {
    LocationRequest locationRequest = new LocationRequest().setInterval(2 * FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS).setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS).setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
    PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
    AsyncTask<PendingResult<LocationSettingsResult>, Void, Boolean> task = new AsyncTask<PendingResult<LocationSettingsResult>, Void, Boolean>() {

        @Override
        @SafeVarargs
        protected final Boolean doInBackground(PendingResult<LocationSettingsResult>... pendingResults) {
            com.google.android.gms.common.api.Status status = pendingResults[0].await().getStatus();
            int statusCode = status.getStatusCode();
            return statusCode == LocationSettingsStatusCodes.SUCCESS || statusCode == LocationSettingsStatusCodes.SUCCESS_CACHE;
        }

        @Override
        protected final void onPostExecute(Boolean success) {
            super.onPostExecute(success);
            if (!success) {
                Log.e(TAG, "Device settings unsuitable for location");
                Toast.makeText(NearbyNotificationService.this, R.string.no_location_enabled, Toast.LENGTH_LONG).show();
                stopSelf();
            }
        }
    };
    //noinspection unchecked
    task.execute(result);
    try {
        LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);
    } catch (SecurityException se) {
        Log.e(TAG, "Still no permission for location services");
        Toast.makeText(this, "Bitte einmal \"in der Nähe\" aufrufen", Toast.LENGTH_LONG).show();
        stopSelf();
    }
}
Also used : LocationRequest(com.google.android.gms.location.LocationRequest) LocationSettingsResult(com.google.android.gms.location.LocationSettingsResult) AsyncTask(android.os.AsyncTask) PendingResult(com.google.android.gms.common.api.PendingResult) LocationSettingsRequest(com.google.android.gms.location.LocationSettingsRequest)

Example 3 with LocationRequest

use of com.google.android.gms.location.LocationRequest in project HumaneApp by Ganesh1010.

the class MapActivity method onConnected.

@Override
public void onConnected(Bundle bundle) {
    mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(1000);
    mLocationRequest.setFastestInterval(1000);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
    if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
    }
}
Also used : LocationRequest(com.google.android.gms.location.LocationRequest)

Example 4 with LocationRequest

use of com.google.android.gms.location.LocationRequest in project cw-omnibus by commonsguy.

the class WeatherFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);
    template = getActivity().getString(R.string.url);
    request = new LocationRequest().setNumUpdates(1).setExpirationDuration(60000).setInterval(1000).setPriority(LocationRequest.PRIORITY_LOW_POWER);
}
Also used : LocationRequest(com.google.android.gms.location.LocationRequest)

Example 5 with LocationRequest

use of com.google.android.gms.location.LocationRequest in project Android-ReactiveLocation by mcharmas.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    lastKnownLocationView = (TextView) findViewById(R.id.last_known_location_view);
    updatableLocationView = (TextView) findViewById(R.id.updated_location_view);
    addressLocationView = (TextView) findViewById(R.id.address_for_location_view);
    currentActivityView = (TextView) findViewById(R.id.activity_recent_view);
    locationProvider = new ReactiveLocationProvider(getApplicationContext());
    lastKnownLocationObservable = locationProvider.getLastKnownLocation();
    final LocationRequest locationRequest = LocationRequest.create().setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY).setNumUpdates(5).setInterval(100);
    locationUpdatesObservable = locationProvider.checkLocationSettings(new LocationSettingsRequest.Builder().addLocationRequest(locationRequest).setAlwaysShow(//Refrence: http://stackoverflow.com/questions/29824408/google-play-services-locationservices-api-new-option-never
    true).build()).doOnNext(new Action1<LocationSettingsResult>() {

        @Override
        public void call(LocationSettingsResult locationSettingsResult) {
            Status status = locationSettingsResult.getStatus();
            if (status.getStatusCode() == LocationSettingsStatusCodes.RESOLUTION_REQUIRED) {
                try {
                    status.startResolutionForResult(MainActivity.this, REQUEST_CHECK_SETTINGS);
                } catch (IntentSender.SendIntentException th) {
                    Log.e("MainActivity", "Error opening settings activity.", th);
                }
            }
        }
    }).flatMap(new Func1<LocationSettingsResult, Observable<Location>>() {

        @Override
        public Observable<Location> call(LocationSettingsResult locationSettingsResult) {
            return locationProvider.getUpdatedLocation(locationRequest);
        }
    });
    addressObservable = locationProvider.getUpdatedLocation(locationRequest).flatMap(new Func1<Location, Observable<List<Address>>>() {

        @Override
        public Observable<List<Address>> call(Location location) {
            return locationProvider.getReverseGeocodeObservable(location.getLatitude(), location.getLongitude(), 1);
        }
    }).map(new Func1<List<Address>, Address>() {

        @Override
        public Address call(List<Address> addresses) {
            return addresses != null && !addresses.isEmpty() ? addresses.get(0) : null;
        }
    }).map(new AddressToStringFunc()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread());
    activityObservable = locationProvider.getDetectedActivity(50);
}
Also used : Status(com.google.android.gms.common.api.Status) LocationRequest(com.google.android.gms.location.LocationRequest) LocationSettingsResult(com.google.android.gms.location.LocationSettingsResult) Address(android.location.Address) LocationSettingsRequest(com.google.android.gms.location.LocationSettingsRequest) List(java.util.List) ReactiveLocationProvider(pl.charmas.android.reactivelocation.ReactiveLocationProvider) Func1(rx.functions.Func1) AddressToStringFunc(pl.charmas.android.reactivelocation.sample.utils.AddressToStringFunc) Location(android.location.Location)

Aggregations

LocationRequest (com.google.android.gms.location.LocationRequest)6 LocationSettingsRequest (com.google.android.gms.location.LocationSettingsRequest)2 LocationSettingsResult (com.google.android.gms.location.LocationSettingsResult)2 Address (android.location.Address)1 Location (android.location.Location)1 AsyncTask (android.os.AsyncTask)1 PendingResult (com.google.android.gms.common.api.PendingResult)1 Status (com.google.android.gms.common.api.Status)1 List (java.util.List)1 ReactiveLocationProvider (pl.charmas.android.reactivelocation.ReactiveLocationProvider)1 AddressToStringFunc (pl.charmas.android.reactivelocation.sample.utils.AddressToStringFunc)1 DisplayTextOnViewAction (pl.charmas.android.reactivelocation.sample.utils.DisplayTextOnViewAction)1 LocationToStringFunc (pl.charmas.android.reactivelocation.sample.utils.LocationToStringFunc)1 Func1 (rx.functions.Func1)1