Example usage for android.location Location getBearing

List of usage examples for android.location Location getBearing

Introduction

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

Prototype

public float getBearing() 

Source Link

Document

Get the bearing, in degrees.

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:Main.java

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

public static void writeLocation(Parcel dest, Location loc) {
    dest.writeString(loc.getProvider());
    dest.writeLong(loc.getTime());//  w  ww  . ja v a  2s  .  c  om
    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: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;// w  w  w .j  a  v  a  2s  .co  m
}

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

private static Object wrapLocation(Location loc) {
    try {/*from  w  w w. java 2  s  .com*/
        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 w w w .  j  ava  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: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());
    }/* w  ww  .  ja v  a  2  s .  c o m*/

    return map;
}

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.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//from w  ww.j av a  2s .c om
 * @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/*from w ww.j av  a  2  s .  com*/
 * @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:org.restcomm.app.utillib.ContentProvider.ContentValuesGenerator.java

/**
 * Creates a ContentValues object with keys taken from {@link Tables.Locations}
 * and values taken from the location object passed as parameter.
 * @param location//from  w  w w  .j a  va 2s. c o m
 * @return
 */
public static ContentValues generateFromLocation(Location location, long stagedEventId, int satellites) {
    /*
     * Note:- A lot of the getters of the location object return 0.0f when the 
     * appropriate data doesn't exist. We replace these by null for the sqlite database.
     */
    ContentValues values = new ContentValues();
    if (location == null)
        location = new Location("");

    //location.setTime(System.currentTimeMillis());
    location.setTime(location.getTime());
    values.put(Tables.Locations.ACCURACY, location.getAccuracy() == 0.0f ? null : location.getAccuracy());
    values.put(Tables.Locations.ALTITUDE, location.getAltitude() == 0.0f ? null : location.getAltitude());
    values.put(Tables.Locations.BEARING, location.getBearing() == 0.0f ? null : location.getBearing());
    values.put(Tables.Locations.LATITUDE, location.getLatitude());
    values.put(Tables.Locations.LONGITUDE, location.getLongitude());
    values.put(Tables.Locations.PROVIDER, location.getProvider());
    values.put(Tables.Locations.SPEED, location.getSpeed() == 0.0f ? null : location.getSpeed());
    values.put(Tables.Locations.TIMESTAMP, location.getTime());
    values.put(Tables.SignalStrengths.EVENT_ID, stagedEventId);
    values.put(Tables.Locations.SATELLITES, satellites);
    //MMCLogger.logToFile(MMCLogger.Level.DEBUG, "ContentValues", "generateFromLocation", "gpsTime="+location.getTime());
    return values;
}