Java Code Examples for android.location.Location#getExtras()
The following examples show how to use
android.location.Location#getExtras() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BackgroundLocation.java From background-geolocation-android with Apache License 2.0 | 6 votes |
public static BackgroundLocation fromLocation(Location location) { BackgroundLocation l = new BackgroundLocation(); l.provider = location.getProvider(); l.latitude = location.getLatitude(); l.longitude = location.getLongitude(); l.time = location.getTime(); l.accuracy = location.getAccuracy(); l.speed = location.getSpeed(); l.bearing = location.getBearing(); l.altitude = location.getAltitude(); l.hasAccuracy = location.hasAccuracy(); l.hasAltitude = location.hasAltitude(); l.hasSpeed = location.hasSpeed(); l.hasBearing = location.hasBearing(); l.extras = location.getExtras(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { l.elapsedRealtimeNanos = location.getElapsedRealtimeNanos(); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { l.setIsFromMockProvider(location.isFromMockProvider()); } return l; }
Example 2
Source File: BackendHelper.java From android_packages_apps_UnifiedNlp with Apache License 2.0 | 6 votes |
private void setLastLocation(Location location) { if (location == null || !location.hasAccuracy()) { return; } if (location.getExtras() == null) { location.setExtras(new Bundle()); } location.getExtras().putString(LOCATION_EXTRA_BACKEND_PROVIDER, location.getProvider()); location.getExtras().putString(LOCATION_EXTRA_BACKEND_COMPONENT, serviceIntent.getComponent().flattenToShortString()); location.setProvider("network"); if (!location.hasAccuracy()) { location.setAccuracy(50000); } if (location.getTime() <= 0) { location.setTime(System.currentTimeMillis()); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { updateElapsedRealtimeNanos(location); } Location noGpsLocation = new Location(location); noGpsLocation.setExtras(null); location.getExtras().putParcelable(LocationProviderBase.EXTRA_NO_GPS_LOCATION, noGpsLocation); lastLocation = location; }
Example 3
Source File: NlpStatusChecks.java From android_packages_apps_UnifiedNlp with Apache License 2.0 | 6 votes |
private boolean isProvidingLastLocation(Context context, ResultCollector collector) { LocationManager locationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE); try { Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); boolean hasKnown = location != null && location.getExtras() != null && location.getExtras().containsKey(LOCATION_EXTRA_BACKEND_COMPONENT); collector.addResult(context.getString(R.string.self_check_name_last_location), hasKnown ? Positive : Unknown, context.getString(R.string.self_check_resolution_last_location)); if (hasKnown) { mLastLocation = location; } return hasKnown; } catch (SecurityException e) { collector.addResult(context.getString(R.string.self_check_name_last_location), Unknown, context.getString(R.string.self_check_loc_perm_missing)); return false; } }
Example 4
Source File: LocationModeSourceActivity.java From TraceByAmap with MIT License | 5 votes |
@Override public void onMyLocationChange(Location location) { // 定位回调监听 if(location != null) { Log.e("amap", "onMyLocationChange 定位成功, lat: " + location.getLatitude() + " lon: " + location.getLongitude()); Bundle bundle = location.getExtras(); if(bundle != null) { int errorCode = bundle.getInt(MyLocationStyle.ERROR_CODE); String errorInfo = bundle.getString(MyLocationStyle.ERROR_INFO); // 定位类型,可能为GPS WIFI等,具体可以参考官网的定位SDK介绍 int locationType = bundle.getInt(MyLocationStyle.LOCATION_TYPE); /* errorCode errorInfo locationType */ Log.e("amap", "定位信息, code: " + errorCode + " errorInfo: " + errorInfo + " locationType: " + locationType ); } else { Log.e("amap", "定位信息, bundle is null "); } } else { Log.e("amap", "定位失败"); } }
Example 5
Source File: MapFragment.java From android_gisapp with GNU General Public License v3.0 | 5 votes |
private void fillTextViews(Location location) { if (null == location) { setDefaultTextViews(); } else { if (location.getProvider().equals(LocationManager.GPS_PROVIDER)) { String text = ""; int satellites = location.getExtras() != null ? location.getExtras().getInt("satellites") : 0; if (satellites > 0) text += satellites; mStatusSource.setText(text); mStatusSource.setCompoundDrawablesWithIntrinsicBounds( ContextCompat.getDrawable(getActivity(), R.drawable.ic_location), null, null, null); } else { mStatusSource.setText(""); mStatusSource.setCompoundDrawablesWithIntrinsicBounds( ContextCompat.getDrawable(getActivity(), R.drawable.ic_signal_wifi), null, null, null); } mStatusAccuracy.setText( String.format(Locale.getDefault(), "%.1f %s", location.getAccuracy(), getString(R.string.unit_meter))); mStatusAltitude.setText( String.format(Locale.getDefault(), "%.1f %s", location.getAltitude(), getString(R.string.unit_meter))); mStatusSpeed.setText( String.format(Locale.getDefault(), "%.1f %s/%s", location.getSpeed() * 3600 / 1000, getString(R.string.unit_kilometer), getString(R.string.unit_hour))); mStatusLatitude.setText( formatCoordinate(location.getLatitude(), R.string.latitude_caption_short)); mStatusLongitude.setText( formatCoordinate(location.getLongitude(), R.string.longitude_caption_short)); } }
Example 6
Source File: MockLocationProvider.java From android_packages_apps_GmsCore with Apache License 2.0 | 5 votes |
public void setLocation(Location mockLocation) { if (mockLocation.getExtras() == null) { mockLocation.setExtras(new Bundle()); } mockLocation.getExtras().putBoolean(KEY_MOCK_LOCATION, false); this.mockLocation = mockLocation; this.changeListener.onLocationChanged(); }
Example 7
Source File: GpsAccuracyDetailsItem.java From open-rmbt with Apache License 2.0 | 5 votes |
@Override public String getCurrent() { if (infoCollector != null) { String locationString = null; final Location loc = infoCollector.getLocationInfo(); if (loc != null) { final int satellites; if (loc.getExtras() != null) { satellites = loc.getExtras().getInt("satellites"); } else { satellites = 0; } locationString = Helperfunctions.convertLocationAccuracy(context.getResources(), loc.hasAccuracy(), loc.getAccuracy(), satellites); locationString += " (" + Helperfunctions.convertLocationTime(loc.getTime()) + ")"; } else { locationString = context.getString(R.string.not_available); } return locationString; } return null; }
Example 8
Source File: LocationUpdateService.java From your-local-weather with GNU General Public License v3.0 | 4 votes |
private org.thosp.yourlocalweather.model.Location processUpdateOfLocation(Location location, Address address) { LocationsDbHelper locationsDbHelper = LocationsDbHelper.getInstance(getBaseContext()); String updateDetailLevel = PreferenceManager.getDefaultSharedPreferences(getBaseContext()).getString( Constants.KEY_PREF_UPDATE_DETAIL, "preference_display_update_nothing"); org.thosp.yourlocalweather.model.Location currentLocation = locationsDbHelper.getLocationByOrderId(0); String currentLocationSource = currentLocation.getLocationSource(); if ("gps".equals(location.getProvider())) { if ((currentLocationSource == null) || !currentLocationSource.contains(getString(R.string.location_weather_update_status_location_from_gps))) { currentLocationSource = getString(R.string.location_weather_update_status_location_from_gps); } } else if (updateDetailLevel.equals("preference_display_update_location_source")) { StringBuilder networkSourceBuilder = new StringBuilder(); networkSourceBuilder.append(getString(R.string.location_weather_update_status_location_from_network)); boolean additionalSourceSetted = false; if ((location.getExtras() != null) && (location.getExtras().containsKey("source"))) { String networkSource = location.getExtras().getString("source"); if (networkSource != null) { if (networkSource.contains("cells")) { networkSourceBuilder.append(getString(R.string.location_weather_update_status_location_from_network_cells)); additionalSourceSetted = true; } if (networkSource.contains("wifis")) { networkSourceBuilder.append(getString(R.string.location_weather_update_status_location_from_network_wifis)); additionalSourceSetted = true; } } } if (!additionalSourceSetted) { networkSourceBuilder.append(location.getProvider().substring(0, 1)); } currentLocationSource = networkSourceBuilder.toString(); appendLog(getBaseContext(), TAG, "send update source to ", currentLocationSource); } else if (getString(R.string.location_weather_update_status_update_started).equals(currentLocationSource)) { currentLocationSource = getString(R.string.location_weather_update_status_location_from_network); } currentLocation = locationsDbHelper.getLocationById(currentLocation.getId()); checkDistanceAndRemoveForecastIfTheNewLocationIsFarAway(location, currentLocation); locationsDbHelper.updateAutoLocationGeoLocation(location.getLatitude(), location.getLongitude(), currentLocationSource, location.getAccuracy(), getLocationTimeInMilis(location)); appendLog(getBaseContext(), TAG, "put new location from location update service, latitude=", location.getLatitude(), ", longitude=", location.getLongitude()); if (address != null) { locationsDbHelper.updateAutoLocationAddress(getBaseContext(), PreferenceUtil.getLanguage(getBaseContext()), address); } else { String geocoder = AppPreference.getLocationGeocoderSource(this); boolean resolveAddressByOS = !"location_geocoder_local".equals(geocoder); Utils.getAndWriteAddressFromGeocoder(new Geocoder(this, new Locale(PreferenceUtil.getLanguage(this))), address, location.getLatitude(), location.getLongitude(), resolveAddressByOS, this); } return currentLocation; }
Example 9
Source File: GpsInfoActivity.java From UsbGps4Droid with GNU General Public License v3.0 | 4 votes |
private void updateData() { boolean running = sharedPreferences.getBoolean(USBGpsProviderService.PREF_START_GPS_PROVIDER, false); if (!isDoublePanel()) { startSwitch.setChecked( running ); } String accuracyValue = "N/A"; String numSatellitesValue = "N/A"; String lat = "N/A"; String lon = "N/A"; String elevation = "N/A"; String gpsTime = "N/A"; String systemTime = "N/A"; Location location = application.getLastLocation(); if (!running) { location = null; } if (location != null) { accuracyValue = String.valueOf(location.getAccuracy()); if (location.getExtras() != null) { numSatellitesValue = String.valueOf(location.getExtras().getInt(NmeaParser.SATELLITE_KEY)); } DecimalFormat df = new DecimalFormat("#.#####"); lat = df.format(location.getLatitude()); lon = df.format(location.getLongitude()); elevation = String.valueOf(location.getAltitude()); gpsTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.US) .format(new Date(location.getTime())); systemTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.US) .format(new Date(location.getExtras().getLong(NmeaParser.SYSTEM_TIME_FIX))); } numSatellites.setText( getString(R.string.number_of_satellites_placeholder, numSatellitesValue) ); accuracyText.setText(getString(R.string.accuracy_placeholder, accuracyValue)); locationText.setText(getString(R.string.location_placeholder, lat, lon)); elevationText.setText(getString(R.string.elevation_placeholder, elevation)); timeText.setText(getString(R.string.gps_time_placeholder, gpsTime, systemTime)); updateLog(); }
Example 10
Source File: LocationHelper.java From android_external_UnifiedNlpApi with Apache License 2.0 | 4 votes |
@Override public double getWeight(Location location) { return location.getExtras() == null ? 1 : location.getExtras().getDouble(EXTRA_WEIGHT, 1); }
Example 11
Source File: LocationHelper.java From android_external_UnifiedNlpApi with Apache License 2.0 | 4 votes |
@Override public double getWeight(Location location) { return location.getExtras() == null ? 1 : location.getExtras().getDouble(EXTRA_WEIGHT, 1); }
Example 12
Source File: MapSectionFragment.java From satstat with GNU General Public License v3.0 | 4 votes |
public static void markLocationAsStale(Location location) { if (location.getExtras() == null) location.setExtras(new Bundle()); location.getExtras().putBoolean(KEY_LOCATION_STALE, true); }
Example 13
Source File: MapSectionFragment.java From satstat with GNU General Public License v3.0 | 3 votes |
/** * Determines if a location is stale. * * A location is considered stale if its Extras have an isStale key set to * True. A location without this key is not considered stale. * * @param location * @return True if stale, False otherwise */ public static boolean isLocationStale(Location location) { Bundle extras = location.getExtras(); if (extras == null) return false; return extras.getBoolean(KEY_LOCATION_STALE); }