List of usage examples for android.location Location setTime
public void setTime(long time)
From source file:Main.java
public static Location readLocation(Parcel in) { Location loc = new Location(in.readString()); loc.setTime(in.readLong()); loc.setLatitude(in.readDouble());/* ww w .j av a2 s .c om*/ 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: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./*w w w. j a 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.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 ww . ja v a 2s. c om*/ * @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; }
From source file:export.format.FacebookCourse.java
private JSONArray trail(long activityId) throws JSONException { final String cols[] = { DB.LOCATION.TYPE, DB.LOCATION.LATITUDE, DB.LOCATION.LONGITUDE, DB.LOCATION.TIME, DB.LOCATION.SPEED };/*ww w .j a v a 2s .c om*/ Cursor c = mDB.query(DB.LOCATION.TABLE, cols, DB.LOCATION.ACTIVITY + " = " + activityId, null, null, null, null); if (c.moveToFirst()) { Location prev = null, last = null; double sumDist = 0; long sumTime = 0; double accTime = 0; final double period = 30; JSONArray arr = new JSONArray(); do { switch (c.getInt(0)) { case DB.LOCATION.TYPE_START: case DB.LOCATION.TYPE_RESUME: last = new Location("Dill"); last.setLatitude(c.getDouble(1)); last.setLongitude(c.getDouble(2)); last.setTime(c.getLong(3)); accTime = period * 1000; // always emit first point // start/resume break; case DB.LOCATION.TYPE_END: accTime = period * 1000; // always emit last point case DB.LOCATION.TYPE_GPS: case DB.LOCATION.TYPE_PAUSE: Location l = new Location("Sill"); l.setLatitude(c.getDouble(1)); l.setLongitude(c.getDouble(2)); l.setTime(c.getLong(3)); if (!c.isNull(4)) l.setSpeed(c.getFloat(4)); if (last != null) { sumDist += l.distanceTo(last); sumTime += l.getTime() - last.getTime(); accTime += l.getTime() - last.getTime(); } prev = last; last = l; } if (Math.round(accTime / 1000) >= period) { arr.put(point(prev, last, sumTime, sumDist)); accTime -= period * 1000; } } while (c.moveToNext()); c.close(); return arr; } c.close(); return null; }
From source file:org.ohmage.reminders.base.TriggerRunTimeDesc.java
public Location getTriggerLocation() { Location loc = new Location(mTrigLocProvider); loc.setLatitude(mTrigLocLat);// w ww . j a va 2 s. c o m loc.setLongitude(mTrigLocLong); loc.setAccuracy(mTrigLocAccuracy); loc.setTime(mTrigLocTime); return loc; }
From source file:org.openbmap.unifiedNlp.Geocoder.OnlineProvider.java
/** * Queries location for list of wifis/*from www . j a va2 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.kylemsguy.fishyfishes.MainActivity.java
public void sendLoc(double lat, double lon) { LocationServices.FusedLocationApi.setMockMode(mGoogleApiClient, true); Location loc = new Location("network"); loc.setLatitude(lat);// w w w. j av a2 s. com loc.setLongitude(lon); System.out.println(loc.toString()); loc.setAccuracy(10); loc.setTime(System.currentTimeMillis()); loc.setElapsedRealtimeNanos(1); LocationServices.FusedLocationApi.setMockLocation(mGoogleApiClient, loc); }
From source file:carsharing.starter.automotive.iot.ibm.com.mobilestarterapp.Home.CarBrowse.java
@Override public void onMapReady(final GoogleMap googleMap) { mMap = googleMap;// ww w . ja v a2s . com mMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() { @Override public void onMapLongClick(final LatLng latLng) { //System.out.println("MAP LONG CLICK " + latLng); final Location location = new Location("NoProvider"); location.setLatitude(latLng.latitude); location.setLongitude(latLng.longitude); location.setTime(new Date().getTime()); String title = ""; if (simulatedLocation == null) { simulatedLocation = location; title = "This location is used next."; } else { simulatedLocation = null; title = "Real location is used next."; } ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(title); final Toast toast = Toast.makeText(getActivity().getApplicationContext(), "Long tap toggles location setting. Go back main menu and come again for the new location!", Toast.LENGTH_LONG); toast.show(); } }); getAccurateLocation(mMap); }
From source file:com.kevinquan.android.location.SimpleRecordedLocation.java
public Location asLocation() { Location location = new Location(TAG); location.setLatitude(mLatitude);/*from w w w. j av a2 s . c o m*/ location.setLongitude(mLongitude); location.setAccuracy(mAccuracy); location.setAltitude(mAltitude); location.setBearing(mBearing); location.setSpeed(mSpeed); location.setTime(mRecordedAt); return location; }
From source file:org.fitchfamily.android.wifi_backend.backend.BackendService.java
private Location wiFiBasedLocation(@NonNull List<WifiAccessPoint> accessPoints) { if (accessPoints.isEmpty()) { return null; } else {/*w ww . j a v a2 s . co m*/ Set<Location> locations = new HashSet<>(accessPoints.size()); for (WifiAccessPoint accessPoint : accessPoints) { SimpleLocation result = database.getLocation(accessPoint.rfId()); if (result != null) { Bundle extras = new Bundle(); extras.putInt(Configuration.EXTRA_SIGNAL_LEVEL, accessPoint.level()); Location location = result.toAndroidLocation(); location.setExtras(extras); locations.add(location); } } if (locations.isEmpty()) { if (DEBUG) { Log.i(TAG, "WifiDBResolver.process(): No APs with known locations"); } return null; } else { // Find largest group of AP locations. If we don't have at // least two near each other then we don't have enough // information to get a good location. locations = LocationUtil.culledAPs(locations, BackendService.this); if (locations == null || locations.size() < 2) { if (DEBUG) { Log.i(TAG, "WifiDBResolver.process(): Insufficient number of WiFi hotspots to resolve location"); } return null; } else { Location avgLoc = LocationUtil.weightedAverage("wifi", locations); if (avgLoc == null) { if (DEBUG) { Log.e(TAG, "Averaging locations did not work."); } return null; } else { avgLoc.setTime(System.currentTimeMillis()); return avgLoc; } } } } }