List of usage examples for android.location Location getAccuracy
public float getAccuracy()
From source file:io.kristal.locationplugin.LocationPlugin.java
/*********************************************************************************************** * * LOCATION LISTENER//w ww. jav a 2 s.c o m * **********************************************************************************************/ @Override public void onLocationChanged(Location location) { if (isBetterLocation(location)) { mBestLocation = location; } if (MODE_ALL.equals(mMode)) { sendLocation(location); } else if (location.getAccuracy() < mAccuracy && location.getTime() > (new Date().getTime() - mTimestamp)) { mLocationManager.removeUpdates(this); if (mTimer != null) { mTimer.cancel(); } sendLocation(location); } }
From source file:com.kevinquan.android.location.SimpleRecordedLocation.java
public SimpleRecordedLocation(Location location, LocationProviderType provider) { this();/*from w w w . j a v a 2 s .c om*/ if (location == null) { Log.w(TAG, "Location provided to construct position was null."); return; } mLatitude = location.getLatitude(); mLongitude = location.getLongitude(); mAccuracy = location.getAccuracy(); mAltitude = location.getAltitude(); mBearing = location.getBearing(); mSpeed = location.getSpeed(); mRecordedAt = location.getTime(); mProvider = provider; }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.webview.CurrentPosition.java
public CurrentPosition() { Prefs prefs = GBApplication.getPrefs(); this.latitude = prefs.getFloat("location_latitude", 0); this.longitude = prefs.getFloat("location_longitude", 0); lastKnownLocation = new Location("preferences"); lastKnownLocation.setLatitude(this.latitude); lastKnownLocation.setLongitude(this.longitude); LOG.info("got longitude/latitude from preferences: " + latitude + "/" + longitude); this.timestamp = System.currentTimeMillis() - 86400000; //let accessor know this value is really old if (ActivityCompat.checkSelfPermission(GBApplication.getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED && prefs.getBoolean("use_updated_location_if_available", false)) { LocationManager locationManager = (LocationManager) GBApplication.getContext() .getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); String provider = null;/*from w ww . j ava2 s . co m*/ if (locationManager != null) { provider = locationManager.getBestProvider(criteria, false); } if (provider != null) { Location lastKnownLocation = locationManager.getLastKnownLocation(provider); if (lastKnownLocation != null) { this.lastKnownLocation = lastKnownLocation; this.timestamp = lastKnownLocation.getTime(); this.timestamp = System.currentTimeMillis() - 1000; //TODO: request updating the location and don't fake its age this.latitude = (float) lastKnownLocation.getLatitude(); this.longitude = (float) lastKnownLocation.getLongitude(); this.accuracy = lastKnownLocation.getAccuracy(); this.altitude = (float) lastKnownLocation.getAltitude(); this.speed = lastKnownLocation.getSpeed(); } } } }
From source file:cmu.troy.applogger.AppService.java
private void logApps(List<String> newApps, List<String> currentApps) throws IOException { /*//from ww w .jav a 2 s .com * Empty newApps means current apps are the same with the last apps. So there is no need to * update last apps file or log file. */ if (newApps == null || newApps.size() == 0) return; lastApps = currentApps; Date now = new Date(); /* Append new Apps into log file */ JSONObject job = new JSONObject(); String id = String.valueOf(now.getTime()); try { job.put(JSONKeys.id, id); job.put(JSONKeys.first, newApps.get(0)); job.put(JSONKeys.log_type, JSONValues.OPEN_AN_APP); /* Log Location block */ Location mLocation = null; if (mLocationClient.isConnected()) mLocation = mLocationClient.getLastLocation(); if (mLocation != null) { job.put(JSONKeys.loc_available, true); job.put(JSONKeys.latitude, mLocation.getLatitude()); job.put(JSONKeys.longitude, mLocation.getLongitude()); job.put(JSONKeys.location_accuracy, mLocation.getAccuracy()); job.put(JSONKeys.location_updated_time, (new Date(mLocation.getTime())).toString()); Date updateTime = new Date(mLocation.getTime()); if ((updateTime.getTime() - now.getTime()) / 60000 > 5) { Tools.runningLog("Last location is too old, a location update is triggered."); LocationRequest request = new LocationRequest(); request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); mLocationClient.requestLocationUpdates(request, new LocationListener() { @Override public void onLocationChanged(Location arg0) { } }); } if (lastLocation == null || lastAddress == null || lastLocation.distanceTo(mLocation) > Tools.SMALL_DISTANCE) { /* Log Address if location is available */ Geocoder geocoder = new Geocoder(this, Locale.getDefault()); List<Address> addresses = null; addresses = geocoder.getFromLocation(mLocation.getLatitude(), mLocation.getLongitude(), 1); if (addresses != null && addresses.size() > 0) { job.put(JSONKeys.addr_available, true); Address address = addresses.get(0); lastAddress = address; job.put(JSONKeys.address, address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : ""); job.put(JSONKeys.city, address.getLocality()); job.put(JSONKeys.country, address.getCountryName()); } else { job.put(JSONKeys.addr_available, false); } } else { job.put(JSONKeys.addr_available, true); job.put(JSONKeys.address, lastAddress.getMaxAddressLineIndex() > 0 ? lastAddress.getAddressLine(0) : ""); job.put(JSONKeys.city, lastAddress.getLocality()); job.put(JSONKeys.country, lastAddress.getCountryName()); } lastLocation = mLocation; } else { if (!mLocationClient.isConnecting()) mLocationClient.connect(); job.put(JSONKeys.loc_available, false); } } catch (JSONException e) { Log.e("JSON", e.toString()); } Tools.logJsonNewBlock(job); }
From source file:com.wikitude.example.SimpleARBrowserActivity.java
/** * listener method called when the location of the user has changed * used for informing the ArchitectView about a new location of the user *///from w ww . ja v a 2 s . c om @Override public void onLocationChanged(Location loc) { // IMPORTANT: // use this method for informing the SDK about a location change by the user // for simplicity not used in this example //inform ArchitectView about location changes if (this.architectView != null) { Toast.makeText(this, "Te moviste!!", Toast.LENGTH_LONG).show(); this.architectView.setLocation((float) (loc.getLatitude()), (float) (loc.getLongitude()), loc.getAccuracy()); } }
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 {//from w w w . j av a2s. c om // 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); }
From source file:info.wncwaterfalls.app.ResultsActivity.java
@Override public void onLocationChanged(Location currentLocation) { mOriginLocation = currentLocation; // Yay! // If the reported accuracy is within 1km, we're good. if (mOriginLocation != null) { float accuracy = currentLocation.getAccuracy(); if (accuracy <= 1000.0) { // Good enough. mOriginAddress = new Address(new Locale("en", "US")); mOriginAddress.setFeatureName("Current Location"); mOriginAddress.setLatitude(mOriginLocation.getLatitude()); mOriginAddress.setLongitude(mOriginLocation.getLongitude()); mFoundOrigin = true;/*from w w w . j a v a 2s .c o m*/ if (mLocationRequestor != null) { // Notify the fragment, which should be sitting there waiting for us, // that we're *finally* done getting the location, which will then // make IT initialize its loader, and call our onWaterfallQuery method. ((ResultsMapFragment) mLocationRequestor).onLocationDetermined(); } else { //Log.d(TAG, "Ooops, lol, requesting fragment is null."); } // Turn off updates. mLocationClient.removeLocationUpdates(this); } else { // Otherwise, we wait for more updates, up to 4. if (mNumUpdates >= 5) { // 5 inaccurate locations. Give up. mLocationClient.removeLocationUpdates(this); mOriginAddress = new Address(new Locale("en", "US")); ((ResultsMapFragment) mLocationRequestor).onLocationDetermined(); } mNumUpdates += 1; } } else { // Lame. mOriginAddress = new Address(new Locale("en", "US")); } }
From source file:com.samknows.measurement.schedule.datacollection.LocationDataCollector.java
private List<JSONObject> locationToPassiveMetric(Location loc) { List<JSONObject> ret = new ArrayList<JSONObject>(); ret.add(PassiveMetric.create(PassiveMetric.METRIC_TYPE.LOCATIONPROVIDER, loc.getTime(), locationType + "")); ret.add(PassiveMetric.create(PassiveMetric.METRIC_TYPE.LATITUDE, loc.getTime(), loc.getLatitude())); ret.add(PassiveMetric.create(PassiveMetric.METRIC_TYPE.LONGITUDE, loc.getTime(), loc.getLongitude())); ret.add(PassiveMetric.create(PassiveMetric.METRIC_TYPE.ACCURACY, loc.getTime(), loc.getAccuracy() + " m")); return ret;//from w w w . j ava 2 s. com }
From source file:upv.welcomeincoming.app.ARViewActivity.java
@SuppressLint("NewApi") @Override// w w w .j a v a 2 s .c o m protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_architect_view); getActionBar().setDisplayHomeAsUpEnabled(true); //Wikitude: Cambio en WebView para Android KitKat if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) { WebView.setWebContentsDebuggingEnabled(true); } } // establecer AR-view this.architectView = (ArchitectView) this.findViewById(R.id.architectView); //Inicializar clave de Wikitude SDK (si se posee) // (en caso contrario, aparece una marca de agua en la architectView) final ArchitectConfig config = new ArchitectConfig("" /* license key */ ); this.architectView.onCreate(config); // listener del locationProvider, maneja los cambios de localizacion this.locationListener = new LocationListener() { @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } @Override public void onLocationChanged(final Location location) { if (location != null) { // establecer ultima localizacion ARViewActivity.this.lastKnownLocaton = location; if (ARViewActivity.this.architectView != null) { // chequeamos si la localizacion tiene altitud a un determinado nivel de exactitud (para invocar al metodo adecuado en la ARView) if (location.hasAltitude() && location.hasAccuracy() && location.getAccuracy() < 7) { ARViewActivity.this.architectView.setLocation(location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getAccuracy()); } else { ARViewActivity.this.architectView.setLocation(location.getLatitude(), location.getLongitude(), location.hasAccuracy() ? location.getAccuracy() : 1000); } } } } }; // locationProvider this.locationProvider = new LocationProvider(this, this.locationListener); }
From source file:com.golfmarin.golf.HoleActivity.java
/** * Location service callback//from w ww.j a v a 2 s . c o m */ @Override public void onLocationChanged(Location location) { Log.i(TAG, "Current location accuracy: " + location.getAccuracy()); // Wait for a usable location if ((location != null) && (location.getAccuracy() < 25.0) && (location.getAccuracy() > 0.0)) { // Find closest course, if just starting up if (startup) { if (getCurrentCourse(location).size() > 0) { currentCourse = (getCurrentCourse(location)).get(0); startup = false; Log.i(TAG, "Current course: " + currentCourse.name); allHoles = currentCourse.holeList; currentHoleNum = 1; currentHole = allHoles.get(0); // progressView.setVisibility(View.GONE); // holeView.setText("Hole"); } } } // Refresh the distances to hole placements if (!startup) updateDisplay(location); }