List of usage examples for android.location Location getAccuracy
public float getAccuracy()
From source file:com.google.android.apps.location.gps.gnsslogger.FileLogger.java
@Override public void onLocationChanged(Location location) { if (location.getProvider().equals(LocationManager.GPS_PROVIDER)) { synchronized (mFileLock) { if (mFileWriter == null) { return; }//from w w w. j a va 2s . c om String locationStream = String.format(Locale.US, "Fix,%s,%f,%f,%f,%f,%f,%d", location.getProvider(), location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getSpeed(), location.getAccuracy(), location.getTime()); try { mFileWriter.write(locationStream); mFileWriter.newLine(); } catch (IOException e) { logException(ERROR_WRITING_FILE, e); } } } }
From source file:digital.dispatch.TaxiLimoNewUI.GCM.GCMIntentService.java
private Location getBestLocation() { Location gpsLocation = getLocationByProvider(LocationManager.GPS_PROVIDER); Location networkLocation = getLocationByProvider(LocationManager.NETWORK_PROVIDER); Location tmpLocation;//from www.ja v a 2s.c o m if (gpsLocation == null) { Logger.v(TAG, "No GPS Location available."); return networkLocation; } if (networkLocation == null) { Logger.v(TAG, "No Network Location available"); return gpsLocation; } Logger.v(TAG, "GPS location:"); Logger.v(TAG, " accurate=" + gpsLocation.getAccuracy() + " time=" + gpsLocation.getTime()); Logger.v(TAG, "Netowrk location:"); Logger.v(TAG, " accurate=" + networkLocation.getAccuracy() + " time=" + networkLocation.getTime()); if (gpsLocation.getAccuracy() < networkLocation.getAccuracy()) { Logger.v(TAG, "use GPS location"); tmpLocation = gpsLocation; } else { Logger.v(TAG, "use networkLocation"); tmpLocation = networkLocation; } return tmpLocation; }
From source file:org.koboc.collect.android.activities.GeoPointMapActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { mLocationCount = savedInstanceState.getInt(LOCATION_COUNT); }/* w w w . j ava 2 s .c o m*/ requestWindowFeature(Window.FEATURE_NO_TITLE); try { setContentView(R.layout.geopoint_layout); } catch (NoClassDefFoundError e) { e.printStackTrace(); Toast.makeText(getBaseContext(), getString(R.string.google_play_services_error_occured), Toast.LENGTH_SHORT).show(); finish(); return; } Intent intent = getIntent(); mLocationAccuracy = GeoPointWidget.DEFAULT_LOCATION_ACCURACY; if (intent != null && intent.getExtras() != null) { if (intent.hasExtra(GeoPointWidget.LOCATION)) { double[] location = intent.getDoubleArrayExtra(GeoPointWidget.LOCATION); mLatLng = new LatLng(location[0], location[1]); } if (intent.hasExtra(GeoPointWidget.ACCURACY_THRESHOLD)) { mLocationAccuracy = intent.getDoubleExtra(GeoPointWidget.ACCURACY_THRESHOLD, GeoPointWidget.DEFAULT_LOCATION_ACCURACY); } mCaptureLocation = !intent.getBooleanExtra(GeoPointWidget.READ_ONLY, false); mRefreshLocation = mCaptureLocation; } /* Set up the map and the marker */ mMarkerOption = new MarkerOptions(); mLocationStatus = (TextView) findViewById(R.id.location_status); /*Zoom only if there's a previous location*/ if (mLatLng != null) { mLocationStatus.setVisibility(View.GONE); mMarkerOption.position(mLatLng); mRefreshLocation = false; // just show this position; don't change it... mZoomed = true; } mCancelLocation = (Button) findViewById(R.id.cancel_location); mCancelLocation.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Collect.getInstance().getActivityLogger().logInstanceAction(this, "cancelLocation", "cancel"); finish(); } }); mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // make sure we have a good location provider before continuing List<String> providers = mLocationManager.getProviders(true); for (String provider : providers) { if (provider.equalsIgnoreCase(LocationManager.GPS_PROVIDER)) { mGPSOn = true; } if (provider.equalsIgnoreCase(LocationManager.NETWORK_PROVIDER)) { mNetworkOn = true; } } if (!mGPSOn && !mNetworkOn) { Toast.makeText(getBaseContext(), getString(R.string.provider_disabled_error), Toast.LENGTH_SHORT) .show(); finish(); } if (mGPSOn) { Location loc = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (loc != null) { InfoLogger.geolog("GeoPointMapActivity: " + System.currentTimeMillis() + " lastKnownLocation(GPS) lat: " + loc.getLatitude() + " long: " + loc.getLongitude() + " acc: " + loc.getAccuracy()); } else { InfoLogger.geolog("GeoPointMapActivity: " + System.currentTimeMillis() + " lastKnownLocation(GPS) null location"); } } if (mNetworkOn) { Location loc = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (loc != null) { InfoLogger.geolog("GeoPointMapActivity: " + System.currentTimeMillis() + " lastKnownLocation(Network) lat: " + loc.getLatitude() + " long: " + loc.getLongitude() + " acc: " + loc.getAccuracy()); } else { InfoLogger.geolog("GeoPointMapActivity: " + System.currentTimeMillis() + " lastKnownLocation(Network) null location"); } } mAcceptLocation = (Button) findViewById(R.id.accept_location); if (mCaptureLocation) { mAcceptLocation.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Collect.getInstance().getActivityLogger().logInstanceAction(this, "acceptLocation", "OK"); returnLocation(); } }); } else { mAcceptLocation.setVisibility(View.GONE); } mReloadLocation = (Button) findViewById(R.id.reload_location); if (mCaptureLocation) { mReloadLocation.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mRefreshLocation = true; mReloadLocation.setVisibility(View.GONE); mLocationStatus.setVisibility(View.VISIBLE); if (mGPSOn) { mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, GeoPointMapActivity.this); } if (mNetworkOn) { mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, GeoPointMapActivity.this); } } }); mReloadLocation.setVisibility(!mRefreshLocation ? View.VISIBLE : View.GONE); } else { mReloadLocation.setVisibility(View.GONE); } // Focuses on marked location mShowLocation = ((Button) findViewById(R.id.show_location)); mShowLocation.setVisibility(View.VISIBLE); mShowLocation.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Collect.getInstance().getActivityLogger().logInstanceAction(this, "showLocation", "onClick"); mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mLatLng, 16)); } }); // not clickable until we have a marker set.... mShowLocation.setClickable(false); }
From source file:com.tagaugmentedreality.utilties.LocationRetriever.java
@SuppressLint("NewApi") @Override//from ww w . j av a 2s. c o m public void onLocationChanged(Location mCurrentLocation) { // TODO Auto-generated method stub latitude = mCurrentLocation.getLatitude(); longitude = mCurrentLocation.getLongitude(); //Toast.makeText(this.context,"updated "+latitude.toString()+" "+longitude.toString()+" "+mCurrentLocation.getAccuracy(), 1000).show(); Log.e("updated", latitude.toString() + " " + longitude.toString() + " " + mCurrentLocation.getProvider() + " " + mCurrentLocation.getAccuracy()); int numberOfInstaces = listenerInstance.size(), k = 0; for (k = 0; k < numberOfInstaces; k++) { if (instanceIdentifier.get(k).equalsIgnoreCase("TL")) {//the tags list has been downloaded, so send it to the TagsList class Log.e("tagAR", "TL"); listenerInstance.get(k).latitudeLongitudeReady(latitude, longitude); } //end if else { Log.e("tagAR ", "not TL"); } //end else } //end for if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { new GetAddressTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } //end if else { new GetAddressTask().execute(); } //end else }
From source file:biz.bokhorst.bpt.BPTService.java
private void sendLocation(Location location) { Bundle b = new Bundle(); b.putDouble("Latitude", location.getLatitude()); b.putDouble("Longitude", location.getLongitude()); b.putDouble("Altitude", location.getAltitude()); b.putFloat("Speed", location.getSpeed()); b.putFloat("Accuracy", location.getAccuracy()); b.putString("Provider", location.getProvider()); b.putLong("Time", location.getTime()); sendMessage(BackPackTrack.MSG_LOCATION, b); }
From source file:com.waz.zclient.pages.main.conversation.LocationFragment.java
@Override public void onLocationChanged(Location location) { Timber.i("onLocationChanged, lat=%f, lon=%f, accuracy=%f, distanceToCurrent=%f", location.getLatitude(), location.getLongitude(), location.getAccuracy(), (currentLocation == null) ? 0 : location.distanceTo(currentLocation)); float distanceFromCenterOfScreen = Float.MAX_VALUE; if (currentLatLng != null) { float[] distance = new float[1]; Location.distanceBetween(currentLatLng.latitude, currentLatLng.longitude, location.getLatitude(), location.getLongitude(), distance); distanceFromCenterOfScreen = distance[0]; Timber.i("current location distance from map center %f", distance[0]); }//from ww w . ja v a2 s .co m currentLocation = location; if (map != null) { map.clear(); LatLng position = new LatLng(location.getLatitude(), location.getLongitude()); map.addMarker(new MarkerOptions().position(position) .icon(BitmapDescriptorFactory.fromBitmap(getMarker())).anchor(0.5f, 0.5f)); if (animateTocurrentLocation && distanceFromCenterOfScreen > DEFAULT_MIMIMUM_CAMERA_MOVEMENT) { if (zoom || animating) { map.animateCamera(CameraUpdateFactory.newLatLngZoom( new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()), DEFAULT_MAP_ZOOM_LEVEL)); animating = true; zoom = false; } else { map.animateCamera(CameraUpdateFactory .newLatLng(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()))); } } } }
From source file:org.akvo.rsr.up.UpdateEditorActivity.java
/** * called by the system when it gets location updates. *///w w w . j a v a2 s.c o m public void onLocationChanged(Location location) { float currentAccuracy = location.getAccuracy(); // if accuracy is 0 then the gps has no idea where we're at if (currentAccuracy > 0) { // If we are below the accuracy treshold, stop listening for updates. // This means that after the geolocation is 'green', it stays the same, // otherwise it keeps on listening if (currentAccuracy <= ACCURACY_THRESHOLD) { LocationManager locMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locMgr.removeUpdates(this); searchingIndicator.setText(R.string.label_gps_ready); gpsProgress.setVisibility(View.GONE); //hide in-progress wheel } // if the location reading is more accurate than the last, update // the view if (lastAccuracy > currentAccuracy || needUpdate) { lastAccuracy = currentAccuracy; needUpdate = false; populateLocation(location); } } else if (needUpdate) { needUpdate = true; populateLocation(location); } }
From source file:com.ut3.ehg.turismotepic.Augmentedreality.java
public void aumentedreality() { poisdb = new rc_pois(getApplicationContext()); poisdb.open();//from w ww.j a v a 2 s . c o m datos = poisdb.getPois(); datos.moveToFirst(); while (!datos.isAfterLast()) { array2.clear(); for (int i = 0; i < 12; i++) { array2.add(datos.getString(i)); } JSONArray conv = new JSONArray(array2); array.add(conv.toString()); datos.moveToNext(); } this.architectView = (ArchitectView) this.findViewById(R.id.architectView); final StartupConfiguration config = new StartupConfiguration(this.getWikitudeSDKLicenseKey(), StartupConfiguration.Features.Geo, this.getCameraPosition()); System.out.println("el resultado de config es " + config); this.architectView.callJavascript("newData('" + array.toString() + "');"); try { this.architectView.onCreate(config); } catch (RuntimeException ex) { this.architectView = null; Toast.makeText(getApplicationContext(), "Tu dispositivo no es compatible con las funciones de realidad aumentada.", Toast.LENGTH_SHORT) .show(); finish(); } this.sensorAccuracyListener = this.getSensorAccuracyListener(); 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) { // forward location updates fired by LocationProvider to architectView, you can set lat/lon from any location-strategy if (location != null) { // sore last location as member, in case it is needed somewhere (in e.g. your adjusted project) Augmentedreality.this.lastKnownLocaton = location; if (Augmentedreality.this.architectView != null) { // check if location has altitude at certain accuracy level & call right architect method (the one with altitude information) if (location.hasAltitude() && location.hasAccuracy() && location.getAccuracy() < 7) { Augmentedreality.this.architectView.setLocation(location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getAccuracy()); } else { Augmentedreality.this.architectView.setLocation(location.getLatitude(), location.getLongitude(), location.hasAccuracy() ? location.getAccuracy() : 1000); } } } } }; this.locationProvider = getLocationProvider(this.locationListener); }
From source file:org.hansel.myAlert.LocationManagement.java
protected boolean isBetterLocation(Location location, Location currentBestLocation) { if (currentBestLocation == null) { return true; }/*from w ww . ja v a 2s .c om*/ long timeDelta = location.getTime() - currentBestLocation.getTime(); boolean isSignificantlyNewer = timeDelta > TWO_MINUTES; boolean isSignificantlyOlder = timeDelta < -TWO_MINUTES; boolean isNewer = timeDelta > 0; if (isSignificantlyNewer) { return true; } else if (isSignificantlyOlder) { return false; } int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy()); boolean isLessAccurate = accuracyDelta > 0; boolean isMoreAccurate = accuracyDelta < 0; boolean isSignificantlyLessAccurate = accuracyDelta > 200; boolean isFromSameProvider = isSameProvider(location.getProvider(), currentBestLocation.getProvider()); if (isMoreAccurate) { return true; } else if (isNewer && !isLessAccurate) { return true; } else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) { return true; } return false; }
From source file:csic.ceab.movelab.beepath.FixGet.java
private void announceFix(Location location, boolean newRecord) { // inform the main display Intent intent = new Intent( getResources().getString(R.string.internal_message_id) + Util.MESSAGE_FIX_RECORDED); // Bundle bundle = new Bundle(); intent.putExtra("lat", (float) location.getLatitude()); intent.putExtra("lng", (float) location.getLongitude()); intent.putExtra("acc", (float) location.getAccuracy()); // intent.putExtras(bundle); sendBroadcast(intent);/*from w w w . j ava2 s . c o m*/ }