Example usage for android.location Location setAccuracy

List of usage examples for android.location Location setAccuracy

Introduction

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

Prototype

public void setAccuracy(float horizontalAccuracy) 

Source Link

Document

Set the estimated horizontal accuracy of this location, meters.

Usage

From source file:Main.java

public static Location createLocation(final double latitude, final double longitude, final float accuracy) {
    Location location = new Location("TestProvider");
    location.setLatitude(latitude);/*  www.  java 2 s.c o  m*/
    location.setLongitude(longitude);
    location.setAccuracy(accuracy);
    return location;
}

From source file:Main.java

/**
 * Create a {@link Location} object from the speified latitude and longitude.
 * @param latitude the latitude for the location to create.
 * @param longitude the longitude for the location to create.
 * @return a {@link Location} object.//from   w ww. ja v  a 2s .co m
 */
public static Location createLocation(double latitude, double longitude) {
    Location location = new Location(LocationManager.NETWORK_PROVIDER);
    location.setLatitude(latitude);
    location.setLongitude(longitude);
    location.setAccuracy(10f);
    location.setTime(System.currentTimeMillis());
    location.setAltitude(0d);
    location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
    return location;
}

From source file:org.mozilla.mozstumbler.service.utils.LocationAdapter.java

public static Location fromJSON(JSONObject jsonObj) {
    Location location = new Location(AppGlobals.LOCATION_ORIGIN_INTERNAL);
    location.setLatitude(getLat(jsonObj));
    location.setLongitude(getLon(jsonObj));
    location.setAccuracy(getAccuracy(jsonObj));
    return location;
}

From source file:Main.java

public static Location readLocation(Parcel in) {
    Location loc = new Location(in.readString());
    loc.setTime(in.readLong());//from  ww  w . jav a  2 s  . com
    loc.setLatitude(in.readDouble());
    loc.setLongitude(in.readDouble());
    loc.setAltitude(in.readDouble());
    loc.setAccuracy(in.readFloat());
    loc.setBearing(in.readFloat());
    loc.setSpeed(in.readFloat());
    return loc;
}

From source file:com.activities.rentalapp.SelectLocationActivity.java

@Override
public void onMapLongClick(LatLng latLng) {
    if (mListener != null) {
        Location location = new Location("LongPressLocationProvider");
        location.setLatitude(latLng.latitude);
        location.setLongitude(latLng.longitude);
        location.setAccuracy(100);
        if (mGoogleMap != null) {
            mGoogleMap.addMarker(new MarkerOptions().position(latLng));
        }//from w w  w.ja va2  s.c  om
        mListener.onLocationChanged(location);
        setResult(Activity.RESULT_OK, new Intent().putExtra("new_Location", location));
        finish();
    }
}

From source file:com.activities.rentalapp.SelectLocationActivity.java

@Override
public void onMapClick(LatLng latLng) {
    if (mListener != null) {
        Location location = new Location("LongPressLocationProvider");
        location.setLatitude(latLng.latitude);
        location.setLongitude(latLng.longitude);
        location.setAccuracy(100);
        mListener.onLocationChanged(location);
        if (mGoogleMap != null) {
            mGoogleMap.addMarker(new MarkerOptions().position(latLng));
            Toast.makeText(getApplicationContext(), "Press Back to take the Selected Location",
                    Toast.LENGTH_SHORT).show();
        }/*from w w w. j a v  a 2s. c om*/
        setResult(Activity.RESULT_OK, new Intent().putExtra("new_Location", location));
    }
}

From source file:org.ohmage.reminders.base.TriggerRunTimeDesc.java

public Location getTriggerLocation() {
    Location loc = new Location(mTrigLocProvider);

    loc.setLatitude(mTrigLocLat);//from w  w  w .  ja v a2 s.c  o  m
    loc.setLongitude(mTrigLocLong);
    loc.setAccuracy(mTrigLocAccuracy);
    loc.setTime(mTrigLocTime);

    return loc;
}

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

/**
 * Converts the Location Message to {@link Location}.
 * @return An {@link Location} with the information of this Message.
 *//*from w w w  . ja  va2 s.  co  m*/
public Location toAndroidLocation() {
    Location location = new Location((String) null);
    location.setLatitude(latitude);
    location.setLongitude(longitude);
    if (hasAltitude) {
        location.setAltitude(altitude);
    }
    if (hasAccuracy) {
        location.setAccuracy(accuracy);
    }
    if (hasBearing) {
        location.setBearing(bearing);
    }
    if (hasSpeed) {
        location.setSpeed(speed);
    }

    return location;
}

From source file:org.openbmap.unifiedNlp.Geocoder.OnlineProvider.java

/**
 * Queries location for list of wifis/*from w  ww  .  jav a 2  s  .  co m*/
 */
@SuppressWarnings("unchecked")
@Override
public void getLocation(List<ScanResult> wifisList, List<Cell> cellsList) {
    ArrayList<String> wifis = new ArrayList<>();

    if (wifisList != null) {
        // Generates a list of wifis from scan results
        for (ScanResult r : wifisList) {
            if ((r.BSSID != null) & !(r.SSID.endsWith("_nomap"))) {
                wifis.add(r.BSSID);
            }
        }
        Log.i(TAG, "Using " + wifis.size() + " wifis for geolocation");
    } else
        Log.i(TAG, "No wifis supplied for geolocation");

    new AsyncTask<Object, Void, JSONObject>() {

        @Override
        protected JSONObject doInBackground(Object... params) {
            if (params == null) {
                throw new IllegalArgumentException("Wifi list was null");
            }
            mWifiQuery = (ArrayList<String>) params[0];
            mCellQuery = new ArrayList<>();
            for (Cell temp : (List<Cell>) params[1]) {
                mCellQuery.add(temp.toString());
            }

            Random r = new Random();
            int idx = r.nextInt(3);

            final String balancer = String.format(REQUEST_URL, new String[] { "a", "b", "c" }[idx]);
            if (mDebug) {
                Log.v(TAG, "Using balancer " + balancer);
            }
            return loadJSON(balancer, (ArrayList<String>) params[0], (List<Cell>) params[1]);
        }

        @Override
        protected void onPostExecute(JSONObject jsonData) {
            if (jsonData == null) {
                Log.e(TAG, "JSON data was null");
                return;
            }

            try {
                Log.i(TAG, "JSON response: " + jsonData.toString());
                String source = jsonData.getString("source");
                JSONObject location = jsonData.getJSONObject("location");
                Double lat = location.getDouble("lat");
                Double lon = location.getDouble("lng");
                Long acc = jsonData.getLong("accuracy");
                Location result = new Location(TAG);
                result.setLatitude(lat);
                result.setLongitude(lon);
                result.setAccuracy(acc);
                result.setTime(System.currentTimeMillis());

                Bundle b = new Bundle();
                b.putString("source", source);
                b.putStringArrayList("bssids", mWifiQuery);
                b.putStringArrayList("cells", mCellQuery);
                result.setExtras(b);

                if (plausibleLocationUpdate(result)) {
                    setLastLocation(result);
                    setLastFix(System.currentTimeMillis());
                    mListener.onLocationReceived(result);
                } else {
                    Log.i(TAG, "Strange location, ignoring");
                }
            } catch (JSONException e) {
                Log.e(TAG, "Error parsing JSON:" + e.getMessage());
            }
        }

        public JSONObject loadJSON(String url, ArrayList<String> wifiParams, List<Cell> cellParams) {
            // Creating JSON Parser instance
            JSONParser jParser = new JSONParser();
            JSONObject params = buildParams(wifiParams, cellParams);
            return jParser.getJSONFromUrl(url, params);
        }

        /**
         * Builds a JSON array with cell and wifi query
         * @param wifis ArrayList containing bssids
         * @param cells
         * @return JSON object
         */
        public JSONObject buildParams(ArrayList<String> wifis, List<Cell> cells) {
            JSONObject root = new JSONObject();
            try {
                // add wifi objects
                JSONArray jsonArray = new JSONArray();
                if (mDebug) {
                    JSONObject object = new JSONObject();
                    object.put("debug", "1");
                    jsonArray.put(object);
                }

                for (String s : wifis) {
                    JSONObject object = new JSONObject();
                    object.put("macAddress", s);
                    object.put("signalStrength", "-54");
                    jsonArray.put(object);
                }
                if (jsonArray.length() > 0) {
                    root.put("wifiAccessPoints", jsonArray);
                }

                // add cell objects
                jsonArray = new JSONArray();
                for (Cell s : cells) {
                    JSONObject object = new JSONObject();
                    object.put("cellId", s.cellId);
                    object.put("locationAreaCode", s.area);
                    object.put("mobileCountryCode", s.mcc);
                    object.put("mobileNetworkCode", s.mnc);
                    jsonArray.put(object);
                }
                if (jsonArray.length() > 0) {
                    root.put("cellTowers", jsonArray);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            Log.v(TAG, "Query param: " + root.toString());
            return root;
        }
    }.execute(wifis, cellsList);
}

From source file:com.kevinquan.android.location.SimpleRecordedLocation.java

public Location asLocation() {
    Location location = new Location(TAG);
    location.setLatitude(mLatitude);/*from  w w  w  . ja v  a 2s  .  co  m*/
    location.setLongitude(mLongitude);
    location.setAccuracy(mAccuracy);
    location.setAltitude(mAltitude);
    location.setBearing(mBearing);
    location.setSpeed(mSpeed);
    location.setTime(mRecordedAt);
    return location;
}