Example usage for android.location Location getExtras

List of usage examples for android.location Location getExtras

Introduction

In this page you can find the example usage for android.location Location getExtras.

Prototype

public Bundle getExtras() 

Source Link

Document

Returns additional provider-specific information about the location fix as a Bundle.

Usage

From source file:de.ncoder.sensorsystem.android.logging.JSONUtils.java

private static Object wrapLocation(Location loc) {
    try {/*w w w  .j  a v  a2s.  c  o m*/
        JSONObject json = new JSONObject();
        json.put("provider", loc.getProvider());
        json.put("latitude", loc.getLatitude());
        json.put("longitude", loc.getLongitude());
        if (loc.hasAccuracy())
            json.put("accuracy", loc.getAccuracy());
        json.put("time", loc.getTime());
        if (loc.hasAltitude())
            json.put("alt", loc.getAltitude());
        if (loc.hasSpeed())
            json.put("vel", loc.getSpeed());
        if (loc.hasBearing())
            json.put("bear", loc.getBearing());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
            if (loc.isFromMockProvider())
                json.put("mock", true);
        if (loc.getExtras() != null) {
            json.put("extra", wrap(loc.getExtras()));
        }
        return json;
    } catch (JSONException e) {
        return loc.toString() + " threw " + e.toString();
    }
}

From source file:com.nextgis.forestinspector.fragment.MapFragment.java

protected void fillTextViews(Location location) {
    if (null == location) {
        setDefaultTextViews();/*  ww  w  .  ja va  2 s .  c om*/
    } else {
        if (location.getProvider().equals(LocationManager.GPS_PROVIDER)) {
            int satellites = location.getExtras().getInt("satellites");
            if (satellites < GpsEventSource.MIN_SATELLITES_IN_FIX) {
                mStatusSource.setText("");
                mStatusSource.setCompoundDrawablesWithIntrinsicBounds(
                        getResources().getDrawable(R.drawable.ic_location), null, null, null);
            } else {
                mStatusSource.setText(satellites + "");
                mStatusSource.setCompoundDrawablesWithIntrinsicBounds(
                        getResources().getDrawable(R.drawable.ic_location), null, null, null);
            }
        } else {
            mStatusSource.setText("");
            mStatusSource.setCompoundDrawablesWithIntrinsicBounds(
                    getResources().getDrawable(R.drawable.ic_signal_wifi), null, null, null);
        }

        mStatusAccuracy
                .setText(String.format("%.1f %s", location.getAccuracy(), getString(R.string.unit_meter)));
        mStatusAltitude
                .setText(String.format("%.1f %s", location.getAltitude(), getString(R.string.unit_meter)));
        mStatusSpeed.setText(String.format("%.1f %s/%s", location.getSpeed() * 3600 / 1000,
                getString(R.string.unit_kilometer), getString(R.string.unit_hour)));
        mStatusLatitude.setText(LocationUtil.formatCoordinate(location.getLatitude(), mCoordinatesFormat) + " "
                + getString(R.string.latitude_caption_short));
        mStatusLongitude.setText(LocationUtil.formatCoordinate(location.getLongitude(), mCoordinatesFormat)
                + " " + getString(R.string.longitude_caption_short));
    }
}

From source file:org.microg.gms.location.GoogleLocationManager.java

public Location getLocation(boolean gpsPermission, boolean networkPermission) {
    if (mockProvider.getLocation() != null)
        return mockProvider.getLocation();
    if (gpsPermission) {
        Location network = networkProvider == null ? null : networkProvider.getLastLocation();
        Location gps = gpsProvider == null ? null : gpsProvider.getLastLocation();
        if (network == null)
            return gps;
        if (gps == null)
            return network;
        if (gps.getTime() > network.getTime() - SWITCH_ON_FRESHNESS_CLIFF_MS)
            return gps;
        return network;
    } else if (networkPermission) {
        Location network = networkProvider == null ? null : networkProvider.getLastLocation();
        if (network != null && network.getExtras() != null
                && network.getExtras().getParcelable("no_gps_location") instanceof Location) {
            network = network.getExtras().getParcelable("no_gps_location");
        }//from w  w w. jav  a 2 s. c  o m
        return network;
    }
    return null;
}

From source file:com.umaps.gpslogger.GpsLoggingService.java

private void AdjustAltitude(Location loc) {

    if (!loc.hasAltitude()) {
        return;//from  w  w w .  j  av a2 s.co m
    }

    if (AppSettings.shouldAdjustAltitudeFromGeoIdHeight() && loc.getExtras() != null) {
        String geoidheight = loc.getExtras().getString("GEOIDHEIGHT");
        if (!Utilities.IsNullOrEmpty(geoidheight)) {
            loc.setAltitude((float) loc.getAltitude() - Float.valueOf(geoidheight));
        }
    }

    loc.setAltitude(loc.getAltitude() - AppSettings.getSubtractAltitudeOffset());
}

From source file:com.crearo.gpslogger.GpsLoggingService.java

private void adjustAltitude(Location loc) {

    if (!loc.hasAltitude()) {
        return;/*from ww  w.j a v a  2 s  . c o m*/
    }

    if (preferenceHelper.shouldAdjustAltitudeFromGeoIdHeight() && loc.getExtras() != null) {
        String geoidheight = loc.getExtras().getString("GEOIDHEIGHT");
        if (!Strings.isNullOrEmpty(geoidheight)) {
            loc.setAltitude((float) loc.getAltitude() - Float.valueOf(geoidheight));
        } else {
            //If geoid height not present for adjustment, don't record an elevation at all.
            loc.removeAltitude();
        }
    }

    if (loc.hasAltitude()) {
        loc.setAltitude(loc.getAltitude() - preferenceHelper.getSubtractAltitudeOffset());
    }
}

From source file:com.mjhram.geodata.GpsLoggingService.java

private void AdjustAltitude(Location loc) {

    if (!loc.hasAltitude()) {
        return;//  ww w  . jav a 2  s  .  c  o  m
    }

    if (AppSettings.shouldAdjustAltitudeFromGeoIdHeight() && loc.getExtras() != null) {
        String geoidheight = loc.getExtras().getString("GEOIDHEIGHT");
        if (!Utilities.IsNullOrEmpty(geoidheight)) {
            loc.setAltitude((float) loc.getAltitude() - Float.valueOf(geoidheight));
        } else {
            //If geoid height not present for adjustment, don't record an elevation at all.
            loc.removeAltitude();
        }
    }

    if (loc.hasAltitude()) {
        loc.setAltitude(loc.getAltitude() - AppSettings.getSubtractAltitudeOffset());
    }
}

From source file:com.transistorsoft.cordova.bggeo.CDVBackgroundGeolocation.java

/**
 * EventBus listener//from  w w w  .  ja v  a 2  s .  c  om
 * @param {Location} location
 */
@Subscribe
public void onEventMainThread(Location location) {
    JSONObject locationData = BackgroundGeolocationService.locationToJson(location, currentActivity);

    Bundle meta = location.getExtras();
    if (meta != null) {
        String action = meta.getString("action");
        boolean motionChanged = action.equalsIgnoreCase(BackgroundGeolocationService.ACTION_ON_MOTION_CHANGE);
        if (motionChanged) {
            boolean nowMoving = meta.getBoolean("isMoving");
            onMotionChange(nowMoving, locationData);
        }
    }
    this.onLocationChange(locationData);
}

From source file:com.vonglasow.michael.satstat.MainActivity.java

public static void markLocationAsStale(Location location) {
    if (location.getExtras() == null)
        location.setExtras(new Bundle());
    location.getExtras().putBoolean(KEY_LOCATION_STALE, true);
}

From source file:com.vonglasow.michael.satstat.MainActivity.java

/**
 * Determines if a location is stale./*from  w  ww .j a v  a  2  s . c  o m*/
 * 
 * A location is considered stale if its Extras have an isStale key set to
 * True. A location without this key is not considered stale.
 * 
 * @param location
 * @return True if stale, False otherwise
 */
public static boolean isLocationStale(Location location) {
    Bundle extras = location.getExtras();
    if (extras == null)
        return false;
    return extras.getBoolean(KEY_LOCATION_STALE);
}

From source file:com.geotrackin.gpslogger.GpsLoggingService.java

/**
 * This event is raised when the GeneralLocationListener has a new location.
 * This method in turn updates notification, writes to file, reobtains
 * preferences, notifies main service client and resets location managers.
 *
 * @param loc Location object// w ww .ja v a 2 s.c  o  m
 */
void OnLocationChanged(Location loc) {

    if (!Session.isStarted()) {
        tracer.debug("OnLocationChanged called, but Session.isStarted is false");
        StopLogging();
        return;
    }

    long currentTimeStamp = System.currentTimeMillis();

    // Don't log a point until the user-defined time has elapsed
    // However, if user has set an annotation, just log the point, disregard any filters
    if (!Session.hasDescription() && !Session.isSinglePointMode()
            && (currentTimeStamp - Session.getLatestTimeStamp()) < (AppSettings.getMinimumSeconds() * 1000)) {
        return;
    }

    if (!isFromValidListener(loc)) {
        return;
    }

    tracer.debug("GpsLoggingService.OnLocationChanged");
    boolean isPassiveLocation = loc.getExtras().getBoolean("PASSIVE");

    // Don't do anything until the user-defined accuracy is reached
    // However, if user has set an annotation, just log the point, disregard any filters
    if (!Session.hasDescription() && AppSettings.getMinimumAccuracyInMeters() > 0) {

        //Don't apply the retry interval to passive locations
        if (!isPassiveLocation && AppSettings.getMinimumAccuracyInMeters() < Math.abs(loc.getAccuracy())) {

            if (this.firstRetryTimeStamp == 0) {
                this.firstRetryTimeStamp = System.currentTimeMillis();
            }

            if (currentTimeStamp - this.firstRetryTimeStamp <= AppSettings.getRetryInterval() * 1000) {
                tracer.warn("Only accuracy of " + String.valueOf(Math.floor(loc.getAccuracy()))
                        + " m. Point discarded.");
                SetStatus("Inaccurate point discarded.");
                //return and keep trying
                return;
            }

            if (currentTimeStamp - this.firstRetryTimeStamp > AppSettings.getRetryInterval() * 1000) {
                tracer.warn("Only accuracy of " + String.valueOf(Math.floor(loc.getAccuracy()))
                        + " m and timeout reached");
                SetStatus("Inaccurate points discarded and retries timed out.");
                //Give up for now
                StopManagerAndResetAlarm();

                //reset timestamp for next time.
                this.firstRetryTimeStamp = 0;
                return;
            }

            //Success, reset timestamp for next time.
            this.firstRetryTimeStamp = 0;
        }
    }

    //Don't do anything until the user-defined distance has been traversed
    // However, if user has set an annotation, just log the point, disregard any filters
    if (!Session.hasDescription() && !Session.isSinglePointMode()
            && AppSettings.getMinimumDistanceInMeters() > 0 && Session.hasValidLocation()) {

        double distanceTraveled = Utilities.CalculateDistance(loc.getLatitude(), loc.getLongitude(),
                Session.getCurrentLatitude(), Session.getCurrentLongitude());

        if (AppSettings.getMinimumDistanceInMeters() > distanceTraveled) {
            SetStatus("Only " + String.valueOf(Math.floor(distanceTraveled)) + " m traveled. Point discarded.");
            tracer.warn(
                    "Only " + String.valueOf(Math.floor(distanceTraveled)) + " m traveled. Point discarded.");
            StopManagerAndResetAlarm();
            return;
        }
    }

    tracer.info("Location to update: " + String.valueOf(loc.getLatitude()) + ","
            + String.valueOf(loc.getLongitude()));
    ResetCurrentFileName(false);
    Session.setLatestTimeStamp(System.currentTimeMillis());
    Session.setCurrentLocationInfo(loc);
    SetDistanceTraveled(loc);
    ShowNotification();

    if (isPassiveLocation) {
        tracer.debug("Logging passive location to file");
    }

    WriteToFile(loc);
    GetPreferences();
    StopManagerAndResetAlarm();

    if (IsMainFormVisible()) {

        mainServiceClient.OnLocationUpdate(loc);
    }

    if (Session.isSinglePointMode()) {
        tracer.debug("Single point mode - stopping logging now");
        StopLogging();
    }
}