Example usage for android.location Location hasSpeed

List of usage examples for android.location Location hasSpeed

Introduction

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

Prototype

public boolean hasSpeed() 

Source Link

Document

True if this location has a speed.

Usage

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

private static Object wrapLocation(Location loc) {
    try {/*from  w  w w .  j  a  v a 2s  .  co 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:uk.ac.horizon.ug.exploding.client.LocationUtils.java

public static void registerOnThread(Context context, LocationListener locationCallback, Listener listener) {
    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    List<String> providers = locationManager.getAllProviders();
    Log.i(TAG, "Found " + providers.size() + " location providers");
    for (String provider : providers) {
        if (locationManager.isProviderEnabled(provider)) {
            Log.i(TAG, "Provider " + provider + " enabled");
        } else {//from   ww w.  j  a v  a 2 s  .  c o  m
            Log.i(TAG, "Provider " + provider + " disabled");
        }
    }
    for (int pi = 0; pi < PROVIDERS.length; pi++) {
        String provider = PROVIDERS[pi];
        if (locationManager.isProviderEnabled(provider)) {
            Log.i(TAG, "Registering with provider " + provider);
            Location loc = locationManager.getLastKnownLocation(provider);
            if (loc != null) {
                Log.i(TAG,
                        "Last Location, provider=" + loc.getProvider() + ", lat=" + loc.getLatitude()
                                + ", long=" + loc.getLongitude() + ", bearing="
                                + (loc.hasBearing() ? "" + loc.getBearing() : "NA") + ", speed="
                                + (loc.hasSpeed() ? "" + loc.getSpeed() : "NA") + ", accuracy="
                                + (loc.hasAccuracy() ? "" + loc.getAccuracy() : "NA") + ", alt="
                                + (loc.hasAltitude() ? "" + loc.getAltitude() : "NA"));

                ZoneService.updateLocation(context, loc);

            }
            //if (!"passive".equals(provider))
            if (locationCallback != null)
                locationManager.requestLocationUpdates(provider, 0/*minTime*/, 0/*minDistance*/,
                        locationCallback);
        } else
            Log.e(TAG, "Required provider " + provider + " not enabled!");
    }
    if (listener != null)
        locationManager.addGpsStatusListener(listener);
}

From source file:ch.luethi.skylinestracker.PositionService.java

@Override
public void onLocationChanged(Location location) {
    if (location.getLatitude() != 0.0) {
        if (isOnline()) {
            app.lastLat = location.getLatitude();
            app.lastLon = location.getLongitude();
            // convert m/sec to km/hr
            float kmPerHr = location.hasSpeed() ? location.getSpeed() * 3.6F : Float.NaN;
            float[] accelVals = null;
            float vspd = Float.NaN;
            getOrCreateSkyLinesTrackingWriter().emitPosition(location.getTime(), app.lastLat, app.lastLon,
                    location.hasAltitude() ? (float) location.getAltitude() : Float.NaN,
                    (int) location.getBearing(), kmPerHr, accelVals, vspd);
            if (app.guiActive) {
                sendPositionStatus();/*from ww w .  jav a  2 s  . c om*/
            }
        } else {
            if (app.guiActive)
                sendConnectionStatus();
        }
    }
}

From source file:org.skt.runtime.original.GeoBroker.java

public JSONObject returnLocationJSON(Location loc) {
    JSONObject o = new JSONObject();

    try {//from  ww  w .  j a  v a2 s.c  om
        o.put("latitude", loc.getLatitude());
        o.put("longitude", loc.getLongitude());
        o.put("altitude", (loc.hasAltitude() ? loc.getAltitude() : null));
        o.put("accuracy", loc.getAccuracy());
        o.put("heading", (loc.hasBearing() ? (loc.hasSpeed() ? loc.getBearing() : null) : null));
        o.put("speed", loc.getSpeed());
        o.put("timestamp", loc.getTime());
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return o;
}

From source file:org.apache.cordova.geolocation.GeoBroker.java

public JSONObject returnLocationJSON(Location loc) {
    JSONObject o = new JSONObject();

    try {/*  ww w  . j a va2s  . co  m*/
        o.put("latitude", loc.getLatitude());
        o.put("longitude", loc.getLongitude());
        o.put("altitude", (loc.hasAltitude() ? loc.getAltitude() : null));
        o.put("accuracy", loc.getAccuracy());
        o.put("heading", (loc.hasBearing() ? (loc.hasSpeed() ? loc.getBearing() : null) : null));
        o.put("velocity", loc.getSpeed());
        o.put("timestamp", loc.getTime());
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return o;
}

From source file:fr.louisbl.cordova.gpslocation.CordovaGPSLocation.java

public JSONObject returnLocationJSON(Location loc) {
    JSONObject o = new JSONObject();

    try {//  w w  w.ja  va  2  s .c  o m
        o.put("latitude", loc.getLatitude());
        o.put("longitude", loc.getLongitude());
        o.put("altitude", (loc.hasAltitude() ? loc.getAltitude() : null));
        o.put("accuracy", loc.getAccuracy());
        o.put("heading", (loc.hasBearing() ? (loc.hasSpeed() ? loc.getBearing() : null) : null));
        o.put("velocity", loc.getSpeed());
        o.put("timestamp", loc.getTime());
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return o;
}

From source file:export.format.FacebookCourse.java

private JSONObject point(Location prev, Location last, long sumTime, double sumDist) throws JSONException {
    JSONObject obj = new JSONObject();
    obj.put("location",
            new JSONObject().put("latitude", last.getLatitude()).put("longitude", last.getLongitude()));
    obj.put("distance", new JSONObject().put("value", sumDist / 1000.0).put("units", "km"));
    obj.put("timestamp", formatTime(last.getTime()));
    if (last.hasSpeed() && last.getSpeed() > 0) {
        obj.put("pace", pace(1.0f / last.getSpeed()));
    }//from w  ww .  j ava2s  . co m
    return obj;
}

From source file:at.alladin.rmbt.android.util.InformationCollector.java

public static JSONObject fillBasicInfo(JSONObject object, Context ctx) throws JSONException {
    object.put("plattform", PLATTFORM_NAME);
    object.put("os_version",
            android.os.Build.VERSION.RELEASE + "(" + android.os.Build.VERSION.INCREMENTAL + ")");
    object.put("api_level", String.valueOf(android.os.Build.VERSION.SDK_INT));
    object.put("device", android.os.Build.DEVICE);
    object.put("model", android.os.Build.MODEL);
    object.put("product", android.os.Build.PRODUCT);
    object.put("language", Locale.getDefault().getLanguage());
    object.put("timezone", TimeZone.getDefault().getID());
    object.put("softwareRevision", RevisionHelper.getVerboseRevision());
    PackageInfo pInfo = getPackageInfo(ctx);
    if (pInfo != null) {
        object.put("softwareVersionCode", pInfo.versionCode);
        object.put("softwareVersionName", pInfo.versionName);
    }/*from  w w w .  j  a  v  a 2s. c  o  m*/
    object.put("type", at.alladin.rmbt.android.util.Config.RMBT_CLIENT_TYPE);

    if (BASIC_INFORMATION_INCLUDE_LOCATION) {
        Location loc = GeoLocation.getLastKnownLocation(ctx);
        if (loc != null) {
            JSONObject locationJson = new JSONObject();
            locationJson.put("lat", loc.getLatitude());
            locationJson.put("long", loc.getLongitude());
            locationJson.put("provider", loc.getProvider());
            if (loc.hasSpeed())
                locationJson.put("speed", loc.getSpeed());
            if (loc.hasAltitude())
                locationJson.put("altitude", loc.getAltitude());
            locationJson.put("age", System.currentTimeMillis() - loc.getTime()); //getElapsedRealtimeNanos() would be better, but require higher API-level
            if (loc.hasAccuracy())
                locationJson.put("accuracy", loc.getAccuracy());
            if (loc.hasSpeed())
                locationJson.put("speed", loc.getSpeed());
            /*
             *  would require API level 18
            if (loc.isFromMockProvider())
               locationJson.put("mock",loc.isFromMockProvider());
            */
            object.put("location", locationJson);
        }
    }

    InformationCollector infoCollector = null;

    if (ctx instanceof RMBTMainActivity) {
        Fragment curFragment = ((RMBTMainActivity) ctx).getCurrentFragment();
        if (curFragment != null) {
            if (curFragment instanceof RMBTMainMenuFragment) {
                infoCollector = ((RMBTMainMenuFragment) curFragment).getInformationCollector();
            }
        }
    }

    if (BASIC_INFORMATION_INCLUDE_LAST_SIGNAL_ITEM && (infoCollector != null)) {
        SignalItem signalItem = infoCollector.getLastSignalItem();
        if (signalItem != null) {
            object.put("last_signal_item", signalItem.toJson());
        } else {
            object.put("last_signal_item", JSONObject.NULL);
        }
    }

    return object;
}

From source file:to.sven.androidrccar.common.communication.model.LocationMessage.java

/**
 * Creates a new {@link LocationMessage} from a {@link Location}.
 * @param location An {@link Location}/*from ww w.  j  av  a2  s . com*/
 * @param sendPosition Is it allowed to send the Position?
 * @param sendSpeed Is it allowed to send the Speed?
 * @param sendBearing Is it allowed to send the Bearing?
 */
public LocationMessage(Location location, boolean sendPosition, boolean sendBearing, boolean sendSpeed) {
    this((sendPosition) ? location.getLatitude() : 0, (sendPosition) ? location.getLongitude() : 0,
            location.hasAltitude() && sendPosition, (sendPosition) ? location.getAltitude() : 0,
            location.hasAccuracy() && sendPosition, (sendPosition) ? location.getAccuracy() : 0,
            location.hasBearing() && sendBearing, (sendBearing) ? location.getBearing() : 0,
            location.hasSpeed() && sendSpeed, (sendSpeed) ? location.getSpeed() : 0);
}

From source file:es.mdelapenya.uned.master.is.ubicomp.sensors.activities.location.BaseGeoLocatedActivity.java

@Override
public void onLocationChanged(Location location) {
    Location currentLocation = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);

    double speed = 0;

    if (lastLocation != null) {
        speed = Math/*w w  w .  ja  v a  2 s . c  om*/
                .sqrt(Math.pow(currentLocation.getLongitude() - lastLocation.getLongitude(), 2)
                        + Math.pow(currentLocation.getLatitude() - lastLocation.getLatitude(), 2))
                / (currentLocation.getTime() - lastLocation.getTime());

        if (currentLocation.hasSpeed()) {
            speed = currentLocation.getSpeed();
        }

        this.speed = new Float(speed);

        lastLocation = currentLocation;

        Metric metric = new SensorMetric(uniqueDeviceId, "sensors-android", currentLocation.getLatitude(),
                currentLocation.getLongitude(), SpeedConverter.convertToKmsh(this.speed), "speed", "km/h",
                new Date().getTime());

        SensorsInteractor sensorsInteractor = new SensorsMetricInteractor(metric);

        new Thread(sensorsInteractor).start();
    }
}