Example usage for android.location Location hasAltitude

List of usage examples for android.location Location hasAltitude

Introduction

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

Prototype

public boolean hasAltitude() 

Source Link

Document

True if this location has an altitude.

Usage

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

private static Object wrapLocation(Location loc) {
    try {/*from  w w  w.ja  v  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:Main.java

public static void setGpsParameters(Parameters parameters, Location loc) {
    // Clear previous GPS location from the parameters.
    parameters.removeGpsData();/* w  w  w  . ja  v  a2  s.  co  m*/

    // We always encode GpsTimeStamp
    parameters.setGpsTimestamp(System.currentTimeMillis() / 1000);

    // Set GPS location.
    if (loc != null) {
        double lat = loc.getLatitude();
        double lon = loc.getLongitude();
        boolean hasLatLon = (lat != 0.0d) || (lon != 0.0d);

        if (hasLatLon) {
            Log.d(TAG, "Set gps location");
            parameters.setGpsLatitude(lat);
            parameters.setGpsLongitude(lon);
            parameters.setGpsProcessingMethod(loc.getProvider().toUpperCase());
            if (loc.hasAltitude()) {
                parameters.setGpsAltitude(loc.getAltitude());
            } else {
                // for NETWORK_PROVIDER location provider, we may have
                // no altitude information, but the driver needs it, so
                // we fake one.
                parameters.setGpsAltitude(0);
            }
            if (loc.getTime() != 0) {
                // Location.getTime() is UTC in milliseconds.
                // gps-timestamp is UTC in seconds.
                long utcTimeSeconds = loc.getTime() / 1000;
                parameters.setGpsTimestamp(utcTimeSeconds);
            }
        } else {
            loc = null;
        }
    }
}

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 {/*  w  w  w . j a v  a2 s  . c  om*/
            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:to.sven.androidrccar.common.communication.model.LocationMessage.java

/**
 * Creates a new {@link LocationMessage} from a {@link Location}.
 * @param location An {@link Location}//from   w  w w .ja v a  2s  .  c  o m
 * @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:org.skt.runtime.original.GeoBroker.java

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

    try {//from   ww  w  .  j  av  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.freedesktop.geoclueshare.LocationService.java

private String getGgaFromLocation(Location location) {
    String gga;/*from   www. j a v  a 2  s.c o  m*/
    Boolean hasAltitude = location.hasAltitude();

    Date date = new Date(location.getTime());
    DateFormat format = new SimpleDateFormat("HHmmss");
    format.setTimeZone(TimeZone.getTimeZone("UTC"));
    String time = format.format(date);

    if (hasAltitude) {
        gga = "$GPGGA,%s,%s,%s,1,,%.1f,%.1f,M,,M,,";
        gga = String.format(gga, time, getLatitudeString(location.getLatitude()),
                getLongitudeString(location.getLongitude()), getHdopFromAccuracy(location.getAccuracy()),
                location.getAltitude());
    } else {
        gga = "$GPGGA,%s,%s,%s,1,,%.1f,,M,,M,,";
        gga = String.format(gga, time, getLatitudeString(location.getLatitude()),
                getLongitudeString(location.getLongitude()), getHdopFromAccuracy(location.getAccuracy()));
    }

    gga = addChecksumToGga(gga);

    return gga;
}

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

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

    try {//  w w  w .j a va  2  s .  com
        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 {/*from  ww  w . j  ava  2  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("velocity", loc.getSpeed());
        o.put("timestamp", loc.getTime());
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return o;
}

From source file:at.fhooe.mc.ba2.wimmer.wikitude.WikitudeMainActivity.java

/**
 * Sets the new location of the ArchitectWorld if the given parameter is not
 * null.//from  w ww . j  a  v  a2s .  c o m
 * 
 * @param location
 *            the new location of the client.
 */
private void setArchitectLocation(Location location) {
    if (location != null) {
        // check if location has altitude at certain accuracy level &
        // call architect method (the one with altitude information)
        if (location.hasAltitude() && location.hasAccuracy() && location.getAccuracy() < 7) {
            mArchitectView.setLocation(location.getLatitude(), location.getLongitude(), location.getAltitude(),
                    location.getAccuracy());
        } else {
            mArchitectView.setLocation(location.getLatitude(), location.getLongitude(),
                    location.hasAccuracy() ? location.getAccuracy() : 1000);
        }
    }
}

From source file:uk.ac.horizon.ubihelper.service.channel.LocationChannel.java

public void onLocationChanged(Location loc) {
    // TODO Auto-generated method stub
    JSONObject value = new JSONObject();
    try {// www . j av  a  2 s.c  o m
        // event time is in nanoseconds
        value.put("timestamp", System.currentTimeMillis());
        value.put("time", loc.getTime());
        value.put("lat", loc.getLatitude());
        value.put("lon", loc.getLongitude());
        value.put("provider", loc.getProvider());
        if (loc.hasAltitude())
            value.put("altitude", loc.getAltitude());
        if (loc.hasAccuracy())
            value.put("accuracy", loc.getAccuracy());
        Log.d(TAG, "onSensorChanged(" + name + "): " + value);
    } catch (JSONException e) {
        /* ignore */
    }
    onNewValue(value);

}