Example usage for android.location Location getSpeed

List of usage examples for android.location Location getSpeed

Introduction

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

Prototype

public float getSpeed() 

Source Link

Document

Get the speed if it is available, in meters/second over ground.

Usage

From source file:Main.java

public static String locationToString(Location location) {
    return "(" + location.getLatitude() + ";" + location.getLongitude() + ")" + " S=" + location.getSpeed()
            + " C=" + location.getBearing() + " A=" + location.getAccuracy();
}

From source file:com.tenforwardconsulting.cordova.bgloc.LocationConverter.java

public static JSONObject toJSONObject(android.location.Location location) throws JSONException {
    JSONObject json = new JSONObject();
    json.put("time", location.getTime());
    json.put("latitude", location.getLatitude());
    json.put("longitude", location.getLongitude());
    json.put("accuracy", location.getAccuracy());
    json.put("speed", location.getSpeed());
    json.put("altitude", location.getAltitude());
    json.put("bearing", location.getBearing());
    return json;/*ww w  .  jav  a  2s  .  co  m*/
}

From source file:Main.java

/***********************************/

public static void writeLocation(Parcel dest, Location loc) {
    dest.writeString(loc.getProvider());
    dest.writeLong(loc.getTime());//  w ww  .  j a  va  2  s .  co m
    dest.writeDouble(loc.getLatitude());
    dest.writeDouble(loc.getLongitude());
    dest.writeDouble(loc.getAltitude());
    dest.writeFloat(loc.getAccuracy());
    dest.writeFloat(loc.getBearing());
    dest.writeFloat(loc.getSpeed());
}

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

private static Object wrapLocation(Location loc) {
    try {//from  w  w w.j av a  2 s .  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.googlecode.android_scripting.jsonrpc.JsonBuilder.java

private static JSONObject buildJsonLocation(Location location) throws JSONException {
    JSONObject result = new JSONObject();
    result.put("altitude", location.getAltitude());
    result.put("latitude", location.getLatitude());
    result.put("longitude", location.getLongitude());
    result.put("time", location.getTime());
    result.put("accuracy", location.getAccuracy());
    result.put("speed", location.getSpeed());
    result.put("provider", location.getProvider());
    result.put("bearing", location.getBearing());
    return result;
}

From source file:com.facebook.react.modules.location.LocationModule.java

private static WritableMap locationToMap(Location location) {
    WritableMap map = Arguments.createMap();
    WritableMap coords = Arguments.createMap();
    coords.putDouble("latitude", location.getLatitude());
    coords.putDouble("longitude", location.getLongitude());
    coords.putDouble("altitude", location.getAltitude());
    coords.putDouble("accuracy", location.getAccuracy());
    coords.putDouble("heading", location.getBearing());
    coords.putDouble("speed", location.getSpeed());
    map.putMap("coords", coords);
    map.putDouble("timestamp", location.getTime());

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        map.putBoolean("mocked", location.isFromMockProvider());
    }/*from  w  w  w  .ja  v a 2s.  co m*/

    return map;
}

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 w  w w  .  j a  va2  s .co 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:com.esri.cordova.geolocation.utils.JSONHelper.java

/**
 * Converts location data into a JSON form that can be consumed within a JavaScript application
 * @param provider Indicates if this location is coming from gps or network provider
 * @param location The android Location//  w  ww .  j  a v a2s  .  com
 * @param cached Indicates if the value was pulled from the device cache or not
 * @return Location data. Note: this library returns 0 rather than null to avoid nullPointExceptions
 */
public static String locationJSON(String provider, Location location, boolean cached) {

    final JSONObject json = new JSONObject();

    if (location != null) {
        try {

            json.put("provider", provider);
            json.put("latitude", location.getLatitude());
            json.put("longitude", location.getLongitude());
            json.put("altitude", location.getAltitude());
            json.put("accuracy", location.getAccuracy());
            json.put("bearing", location.getBearing());
            json.put("speed", location.getSpeed());
            json.put("timestamp", location.getTime());
            json.put("cached", cached);
        } catch (JSONException exc) {
            logJSONException(exc);
        }
    }

    return json.toString();
}

From source file:com.esri.cordova.geolocation.utils.JSONHelper.java

/**
 * Converts location data into a JSON form that can be consumed within a JavaScript application
 * @param provider Indicates if this location is coming from gps or network provider
 * @param location The android Location/*w ww .  j a  v  a 2s  .co  m*/
 * @param cached Indicates if the value was pulled from the device cache or not
 * @param buffer Boolean indicates whether or not buffering is activated
 * @param bufferLat The buffer's geometric latitudinal center.
 * @param bufferedLon The buffer's geometric longitudinal center.
 * @param bufferedAccuracy The buffer's average accuracy.
 * @param bufferSize The number of elements within the buffer
 * @return Location data. Note: this library returns 0 rather than null to avoid nullPointExceptions
 */
public static String locationJSON(String provider, Location location, boolean cached, boolean buffer,
        double bufferLat, double bufferedLon, float bufferedAccuracy, int bufferSize) {

    final JSONObject json = new JSONObject();

    if (location != null) {
        try {

            json.put("provider", provider);
            json.put("timestamp", location.getTime());
            json.put("latitude", location.getLatitude());
            json.put("longitude", location.getLongitude());
            json.put("altitude", location.getAltitude());
            json.put("accuracy", location.getAccuracy());
            json.put("bearing", location.getBearing());
            json.put("speed", location.getSpeed());
            json.put("cached", cached);
            json.put("buffer", buffer);
            json.put("bufferSize", bufferSize);
            json.put("bufferedLatitude", bufferLat);
            json.put("bufferedLongitude", bufferedLon);
            json.put("bufferedAccuracy", bufferedAccuracy);
        } catch (JSONException exc) {
            logJSONException(exc);
        }
    }

    return json.toString();
}

From source file:com.mtramin.awarenessplayground.MainActivity.java

private void setLocation(Location location) {
    String locationText = String.format(Locale.US, "%f/%f - %f (%f km/h)", location.getLatitude(),
            location.getLongitude(), location.getBearing(), location.getSpeed());
    ((TextView) findViewById(R.id.location)).setText(locationText);
}