Example usage for android.location Location getAccuracy

List of usage examples for android.location Location getAccuracy

Introduction

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

Prototype

public float getAccuracy() 

Source Link

Document

Get the estimated horizontal accuracy of this location, radial, in meters.

Usage

From source file:org.altusmetrum.AltosDroid.TabMap.java

public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) {
    if (from_receiver != null) {
        mBearingView.setText(String.format("%3.0f", from_receiver.bearing));
        mDistanceView.setText(String.format("%6.0f m", from_receiver.distance));
    }//from w  ww. jav  a 2  s .  c  o m

    if (state != null) {
        if (mapLoaded) {
            if (state.gps != null) {
                mRocketMarker.setPosition(new LatLng(state.gps.lat, state.gps.lon));
                mRocketMarker.setVisible(true);

                mPolyline.setPoints(Arrays.asList(new LatLng(state.pad_lat, state.pad_lon),
                        new LatLng(state.gps.lat, state.gps.lon)));
                mPolyline.setVisible(true);
            }

            if (state.state == AltosLib.ao_flight_pad) {
                mPadMarker.setPosition(new LatLng(state.pad_lat, state.pad_lon));
                mPadMarker.setVisible(true);
            }
        }
        if (state.gps != null) {
            mTargetLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
            mTargetLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E"));
            if (state.gps.locked && state.gps.nsat >= 4)
                center(state.gps.lat, state.gps.lon, 10);
        }
    }

    if (receiver != null) {
        double accuracy;

        if (receiver.hasAccuracy())
            accuracy = receiver.getAccuracy();
        else
            accuracy = 1000;
        mReceiverLatitudeView.setText(AltosDroid.pos(receiver.getLatitude(), "N", "S"));
        mReceiverLongitudeView.setText(AltosDroid.pos(receiver.getLongitude(), "W", "E"));
        center(receiver.getLatitude(), receiver.getLongitude(), accuracy);
    }

}

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

protected void fillTextViews(Location location) {
    if (null == location) {
        setDefaultTextViews();//from ww w  .  j  a  v a2 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:com.RSMSA.policeApp.OffenceReportForm.java

/**
 * Perform a location update either by force or due to location or distance change
 * @param l/*  ww w. j  av a 2  s .co  m*/
 * @param force
 */
public void doLocationUpdate(Location l, boolean force) {
    long minDistance = 1000;
    Log.d(TAG, "update received:" + l);
    if (l == null) {
        Log.d(TAG, "Empty location");
        if (force)
            Toast.makeText(this, "Current location not available", Toast.LENGTH_SHORT).show();
        return;
    }
    if (lastLocation != null) {
        float distance = l.distanceTo(lastLocation);
        Log.d(TAG, "Distance to last: " + distance);
        if (l.distanceTo(lastLocation) < minDistance && !force) {
            Log.d(TAG, "Position didn't change");
            return;
        }
        if (l.getAccuracy() >= lastLocation.getAccuracy() && l.distanceTo(lastLocation) < l.getAccuracy()
                && !force) {
            Log.d(TAG, "Accuracy got worse and we are still " + "within the accuracy range.. Not updating");
            return;
        }
    }
}

From source file:com.andybotting.tramhunter.activity.StopDetailsActivity.java

/**
 * Upload statistics to our web server/* w w  w. j  a va  2 s  . co m*/
 */
private void uploadStats() {
    if (LOGV)
        Log.i(TAG, "Sending stop request statistics");

    // gather all of the device info
    try {
        TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        String device_uuid = tm.getDeviceId();
        String device_id = "00000000000000000000000000000000";
        if (device_uuid != null) {
            device_id = GenericUtil.MD5(device_uuid);
        }

        LocationManager mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        Location location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

        // post the data
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost("http://tramhunter.andybotting.com/stats/stop/send");
        post.setHeader("Content-Type", "application/x-www-form-urlencoded");

        List<NameValuePair> pairs = new ArrayList<NameValuePair>();
        pairs.add(new BasicNameValuePair("device_id", device_id));
        pairs.add(new BasicNameValuePair("guid", ttService.getGUID()));
        pairs.add(new BasicNameValuePair("ttid", String.valueOf(mStop.getTramTrackerID())));

        if (location != null) {
            pairs.add(new BasicNameValuePair("latitude", String.valueOf(location.getLatitude())));
            pairs.add(new BasicNameValuePair("longitude", String.valueOf(location.getLongitude())));
            pairs.add(new BasicNameValuePair("accuracy", String.valueOf(location.getAccuracy())));
        }

        try {
            post.setEntity(new UrlEncodedFormEntity(pairs));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        try {
            HttpResponse response = client.execute(post);
            response.getStatusLine().getStatusCode();
        } catch (Exception e) {
            e.printStackTrace();
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:edu.missouri.bas.service.SensorService.java

protected void writeLocationToFile(Location l) {

    String toWrite;/*  w ww.  ja  va2 s  .c  om*/
    Calendar cl = Calendar.getInstance();
    SimpleDateFormat curFormater = new SimpleDateFormat("MMMMM_dd");
    String dateObj = curFormater.format(cl.getTime());
    File f = new File(BASE_PATH, "locations." + bluetoothMacAddress + "." + dateObj + ".txt");

    Calendar cal = Calendar.getInstance();
    cal.setTimeZone(TimeZone.getTimeZone("US/Central"));
    toWrite = String.valueOf(cal.getTime()) + "," + l.getLatitude() + "," + l.getLongitude() + ","
            + l.getAccuracy() + "," + l.getProvider() + "," + getNameFromType(currentUserActivity);
    if (f != null) {
        try {
            writeToFile(f, toWrite);
            //sendDatatoServer("locations."+bluetoothMacAddress+"."+dateObj,toWrite);
            //Ricky
            TransmitData transmitData = new TransmitData();
            transmitData.execute("locations." + bluetoothMacAddress + "." + dateObj, toWrite);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.andybotting.tubechaser.activity.StationDetail.java

/**
 * Upload stats// ww w .  j a  v  a2 s  . com
 */
private void uploadStats() {
    if (LOGV)
        Log.v(TAG, "Sending Station/Line statistics");

    // gather all of the device info
    try {
        TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        String device_uuid = tm.getDeviceId();
        String device_id = "00000000000000000000000000000000";
        if (device_uuid != null) {
            device_id = GenericUtil.MD5(device_uuid);
        }

        LocationManager mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        Location location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

        // post the data
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost("http://tubechaser.andybotting.com/stats/depart/send");
        post.setHeader("Content-Type", "application/x-www-form-urlencoded");

        List<NameValuePair> pairs = new ArrayList<NameValuePair>();

        pairs.add(new BasicNameValuePair("device_id", device_id));
        pairs.add(new BasicNameValuePair("station_id", String.valueOf(mStation.getId())));
        pairs.add(new BasicNameValuePair("line_id", String.valueOf(mLine.getId())));

        if (location != null) {
            pairs.add(new BasicNameValuePair("latitude", String.valueOf(location.getLatitude())));
            pairs.add(new BasicNameValuePair("longitude", String.valueOf(location.getLongitude())));
            pairs.add(new BasicNameValuePair("accuracy", String.valueOf(location.getAccuracy())));
        }

        try {
            post.setEntity(new UrlEncodedFormEntity(pairs));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        try {
            HttpResponse response = client.execute(post);
            response.getStatusLine().getStatusCode();
        } catch (Exception e) {
            e.printStackTrace();
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:org.spontaneous.trackservice.RemoteService.java

/**
 * Use the ContentResolver mechanism to store a received location
 *
 * @param location/* w  w w  . j  ava2 s.  co m*/
 */
private void storeLocation(Location location) {

    if (!isLogging()) {
        Log.e(TAG, String.format("Not logging but storing location %s, prepare to fail", location.toString()));
    }
    ContentValues args = new ContentValues();

    args.put(Waypoints.LATITUDE, Double.valueOf(location.getLatitude()));
    args.put(Waypoints.LONGITUDE, Double.valueOf(location.getLongitude()));
    args.put(Waypoints.SPEED, Float.valueOf(location.getSpeed()));
    args.put(Waypoints.TIME, Long.valueOf(System.currentTimeMillis()));
    args.put(Waypoints.DISTANCE, this.mDistance);

    if (location.hasAccuracy()) {
        args.put(Waypoints.ACCURACY, Float.valueOf(location.getAccuracy()));
    }
    if (location.hasAltitude()) {
        args.put(Waypoints.ALTITUDE, Double.valueOf(location.getAltitude()));

    }
    if (location.hasBearing()) {
        args.put(Waypoints.BEARING, Float.valueOf(location.getBearing()));
    }

    Uri waypointInsertUri = Uri.withAppendedPath(Tracks.CONTENT_URI,
            this.mTrackId + "/segments/" + this.mSegmentId + "/waypoints");
    Uri inserted = getContentResolver().insert(waypointInsertUri, args);
    this.mWaypointId = Long.parseLong(inserted.getLastPathSegment());
}

From source file:com.nextgis.maplibui.activity.ModifyAttributesActivity.java

protected void setLocationText(Location location) {
    if (null == mLatView || null == mLongView || null == mAccView || null == mAltView)
        return;/*w w w . ja v  a 2  s.  com*/

    if (null == location) {
        mLatView.setText(formatCoordinates(Double.NaN, R.string.latitude_caption_short));
        mLongView.setText(formatCoordinates(Double.NaN, R.string.longitude_caption_short));
        mAltView.setText(formatMeters(Double.NaN, R.string.altitude_caption_short));
        mAccView.setText(formatMeters(Double.NaN, R.string.accuracy_caption_short));
        return;
    }

    mLocation = location;
    mLatView.setText(formatCoordinates(location.getLatitude(), R.string.latitude_caption_short));
    mLongView.setText(formatCoordinates(location.getLongitude(), R.string.longitude_caption_short));

    mAltView.setText(formatMeters(location.getAltitude(), R.string.altitude_caption_short));
    mAccView.setText(formatMeters(location.getAccuracy(), R.string.accuracy_caption_short));
}

From source file:edu.cens.loci.provider.LociDbUtils.java

/**
 * //from w ww. java2 s.c o m
 * @param time
 * @param loc
 * @return
 */
public long insertPosition(long time, Location loc) {

    final SQLiteDatabase db = mDbHelper.getWritableDatabase();
    ContentValues args = new ContentValues();
    args.put(Tracks.TIME, time);
    args.put(Tracks.LATITUDE, loc.getLatitude());
    args.put(Tracks.LONGITUDE, loc.getLongitude());
    args.put(Tracks.ALTITUDE, loc.getAltitude());
    args.put(Tracks.SPEED, loc.getSpeed());
    args.put(Tracks.ACCURACY, loc.getAccuracy());
    args.put(Tracks.BEARING, loc.getBearing());
    args.put(Tracks.SYNC, 0);

    //MyLog.d(LociConfig.Debug.Provder.DB.LOG_EVENT, TAG, "[Db] insertPosition " + String.format("lat=%7.2f, lon=%7.2f, alt=%7.2f, speed=%7.2f, acc=%7.2f", loc.getLatitude(), loc.getLongitude(), loc.getAltitude(), loc.getSpeed(), loc.getAccuracy()));

    return db.insert(Tables.TRACKS, null, args);
}

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

/**
 * Updates the map view so that all markers are visible.
 *///w w w.  j ava2 s.c  o m
public static void updateMap() {
    boolean needsRedraw = false;
    Dimension dimension = mapMap.getModel().mapViewDimension.getDimension();
    // just trigger a redraw if we're not going to pan or zoom
    if ((dimension == null) || (!isMapViewAttached)) {
        mapMap.getLayerManager().redrawLayers();
        return;
    }
    // move locations into view and zoom out as needed
    int tileSize = mapMap.getModel().displayModel.getTileSize();
    BoundingBox bb = null;
    BoundingBox bb2 = null;
    for (Location l : providerLocations.values())
        if ((l != null) && (l.getProvider() != "")) {
            double lat = l.getLatitude();
            double lon = l.getLongitude();
            double yRadius = l.hasAccuracy() ? ((l.getAccuracy() * 360.0f) / EARTH_CIRCUMFERENCE) : 0;
            double xRadius = l.hasAccuracy() ? (yRadius * Math.abs(Math.cos(lat))) : 0;

            double minLon = Math.max(lon - xRadius, -180);
            double maxLon = Math.min(lon + xRadius, 180);
            double minLat = Math.max(lat - yRadius, -90);
            double maxLat = Math.min(lat + yRadius, 90);

            if (!isLocationStale(l)) {
                // location is up to date, add to main BoundingBox
                if (bb != null) {
                    minLat = Math.min(bb.minLatitude, minLat);
                    maxLat = Math.max(bb.maxLatitude, maxLat);
                    minLon = Math.min(bb.minLongitude, minLon);
                    maxLon = Math.max(bb.maxLongitude, maxLon);
                }
                bb = new BoundingBox(minLat, minLon, maxLat, maxLon);
            } else {
                // location is stale, add to stale BoundingBox
                if (bb2 != null) {
                    minLat = Math.min(bb2.minLatitude, minLat);
                    maxLat = Math.max(bb2.maxLatitude, maxLat);
                    minLon = Math.min(bb2.minLongitude, minLon);
                    maxLon = Math.max(bb2.maxLongitude, maxLon);
                }
                bb2 = new BoundingBox(minLat, minLon, maxLat, maxLon);
            }
        }
    if (bb == null)
        bb = bb2; // all locations are stale, center to them
    if (bb == null) {
        needsRedraw = true;
    } else {
        byte newZoom = LatLongUtils.zoomForBounds(dimension, bb, tileSize);
        if (newZoom < mapMap.getModel().mapViewPosition.getZoomLevel()) {
            mapMap.getModel().mapViewPosition.setZoomLevel(newZoom);
        } else {
            needsRedraw = true;
        }

        MapViewProjection proj = new MapViewProjection(mapMap);
        Point nw = proj.toPixels(new LatLong(bb.maxLatitude, bb.minLongitude));
        Point se = proj.toPixels(new LatLong(bb.minLatitude, bb.maxLongitude));

        // move only if bb is not entirely visible
        if ((nw.x < 0) || (nw.y < 0) || (se.x > dimension.width) || (se.y > dimension.height)) {
            mapMap.getModel().mapViewPosition.setCenter(bb.getCenterPoint());
        } else {
            needsRedraw = true;
        }
    }
    if (needsRedraw)
        mapMap.getLayerManager().redrawLayers();
}