List of usage examples for android.location Location getProvider
public String getProvider()
From source file:Main.java
/***********************************/ public static void writeLocation(Parcel dest, Location loc) { dest.writeString(loc.getProvider()); dest.writeLong(loc.getTime());/* ww w. j a v a2 s . co m*/ dest.writeDouble(loc.getLatitude()); dest.writeDouble(loc.getLongitude()); dest.writeDouble(loc.getAltitude()); dest.writeFloat(loc.getAccuracy()); dest.writeFloat(loc.getBearing()); dest.writeFloat(loc.getSpeed()); }
From source file:de.ncoder.sensorsystem.android.logging.JSONUtils.java
private static Object wrapLocation(Location loc) { try {//from w ww . j av a 2s .c o m JSONObject json = new JSONObject(); json.put("provider", loc.getProvider()); json.put("latitude", loc.getLatitude()); json.put("longitude", loc.getLongitude()); if (loc.hasAccuracy()) json.put("accuracy", loc.getAccuracy()); json.put("time", loc.getTime()); if (loc.hasAltitude()) json.put("alt", loc.getAltitude()); if (loc.hasSpeed()) json.put("vel", loc.getSpeed()); if (loc.hasBearing()) json.put("bear", loc.getBearing()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) if (loc.isFromMockProvider()) json.put("mock", true); if (loc.getExtras() != null) { json.put("extra", wrap(loc.getExtras())); } return json; } catch (JSONException e) { return loc.toString() + " threw " + e.toString(); } }
From source file:Main.java
public static String dumpLocationInfo(Location loc) { if (loc == null) { return "Location null or empty"; }/*from www .j a v a2 s . co m*/ return String.format(Locale.getDefault(), "lat: %f, lng: %f, acc: %f, provider: %s", loc.getLatitude(), loc.getLongitude(), loc.getAccuracy(), loc.getProvider()); }
From source file:com.appdynamics.demo.gasp.utils.LocationServices.java
/** * Enable location checking (via LocationFragment) * @param context the application context *//* w w w. j a va 2s. c o m*/ public static void enableLocationChecking(FragmentActivity context) { try { if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS) { // Check current location Location location = LocationFragment.getLocation(context); if (location != null) { Log.d(TAG, "Location: " + String.format("%.6f", location.getLatitude()) + ", " + String.format("%.6f", location.getLongitude()) + " (via " + location.getProvider() + ")" + '\n'); } // Add LocationFragment to enable location updates FragmentManager fm = context.getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); LocationFragment locationFragment = new LocationFragment(); ft.add(locationFragment, "LocationFragment"); ft.commit(); } else Log.e(TAG, "Google Play Services not available"); } catch (Exception e) { e.printStackTrace(); } }
From source file:uk.ac.horizon.ug.exploding.client.LocationUtils.java
public static void registerOnThread(Context context, LocationListener locationCallback, Listener listener) { LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); List<String> providers = locationManager.getAllProviders(); Log.i(TAG, "Found " + providers.size() + " location providers"); for (String provider : providers) { if (locationManager.isProviderEnabled(provider)) { Log.i(TAG, "Provider " + provider + " enabled"); } else {//from w w w . j a va 2 s .c o m Log.i(TAG, "Provider " + provider + " disabled"); } } for (int pi = 0; pi < PROVIDERS.length; pi++) { String provider = PROVIDERS[pi]; if (locationManager.isProviderEnabled(provider)) { Log.i(TAG, "Registering with provider " + provider); Location loc = locationManager.getLastKnownLocation(provider); if (loc != null) { Log.i(TAG, "Last Location, provider=" + loc.getProvider() + ", lat=" + loc.getLatitude() + ", long=" + loc.getLongitude() + ", bearing=" + (loc.hasBearing() ? "" + loc.getBearing() : "NA") + ", speed=" + (loc.hasSpeed() ? "" + loc.getSpeed() : "NA") + ", accuracy=" + (loc.hasAccuracy() ? "" + loc.getAccuracy() : "NA") + ", alt=" + (loc.hasAltitude() ? "" + loc.getAltitude() : "NA")); ZoneService.updateLocation(context, loc); } //if (!"passive".equals(provider)) if (locationCallback != null) locationManager.requestLocationUpdates(provider, 0/*minTime*/, 0/*minDistance*/, locationCallback); } else Log.e(TAG, "Required provider " + provider + " not enabled!"); } if (listener != null) locationManager.addGpsStatusListener(listener); }
From source file:com.googlecode.android_scripting.jsonrpc.JsonBuilder.java
private static JSONObject buildJsonLocation(Location location) throws JSONException { JSONObject result = new JSONObject(); result.put("altitude", location.getAltitude()); result.put("latitude", location.getLatitude()); result.put("longitude", location.getLongitude()); result.put("time", location.getTime()); result.put("accuracy", location.getAccuracy()); result.put("speed", location.getSpeed()); result.put("provider", location.getProvider()); result.put("bearing", location.getBearing()); return result; }
From source file:Main.java
public static void setGpsParameters(Parameters parameters, Location loc) { // Clear previous GPS location from the parameters. parameters.removeGpsData();//from ww w.j av a2 s .c om // We always encode GpsTimeStamp parameters.setGpsTimestamp(System.currentTimeMillis() / 1000); // Set GPS location. if (loc != null) { double lat = loc.getLatitude(); double lon = loc.getLongitude(); boolean hasLatLon = (lat != 0.0d) || (lon != 0.0d); if (hasLatLon) { Log.d(TAG, "Set gps location"); parameters.setGpsLatitude(lat); parameters.setGpsLongitude(lon); parameters.setGpsProcessingMethod(loc.getProvider().toUpperCase()); if (loc.hasAltitude()) { parameters.setGpsAltitude(loc.getAltitude()); } else { // for NETWORK_PROVIDER location provider, we may have // no altitude information, but the driver needs it, so // we fake one. parameters.setGpsAltitude(0); } if (loc.getTime() != 0) { // Location.getTime() is UTC in milliseconds. // gps-timestamp is UTC in seconds. long utcTimeSeconds = loc.getTime() / 1000; parameters.setGpsTimestamp(utcTimeSeconds); } } else { loc = null; } } }
From source file:com.prey.services.LocationService.java
private void setNewLocation(Location newLocation) { PreyLogger// w w w .j a v a 2s . co m .d("[" + newLocation.getProvider() + "] Fix found!. Accuracy: [" + newLocation.getAccuracy() + "]"); if (lastRegisteredLocation == null) { //PreyLogger.d("-----> First fix. Set as last location!"); lastRegisteredLocation = newLocation; } else { if (newLocation.getTime() - lastRegisteredLocation.getTime() > PreyConfig.LAST_LOCATION_MAX_AGE) { //Last registered fix was set more that 2 minutes ago. It's older so must be updated! //PreyLogger.d("-----> Old fix has expired (older than 2 minutes). Setting new fix as last location!"); lastRegisteredLocation = newLocation; } else if (newLocation.hasAccuracy() && (newLocation.getAccuracy() < lastRegisteredLocation.getAccuracy())) { //New location is more accurate than the previous one. Win! //PreyLogger.d("-------> Newer and more accurate fix. Set as last location!"); lastRegisteredLocation = newLocation; } } PreyLocationManager.getInstance(getApplicationContext()) .setLastLocation(new PreyLocation(lastRegisteredLocation)); }
From source file:com.vonglasow.michael.satstat.PasvLocListenerService.java
@Override public void onLocationChanged(Location location) { if (!location.getProvider().equals(LocationManager.GPS_PROVIDER)) return;/* ww w .j av a 2 s. co m*/ if (mNotifyFix && (mStatus != GPS_INACTIVE)) { mStatus = GPS_FIX; GpsStatus status = mLocationManager.getGpsStatus(null); int satsInView = 0; int satsUsed = 0; Iterable<GpsSatellite> sats = status.getSatellites(); for (GpsSatellite sat : sats) { satsInView++; if (sat.usedInFix()) { satsUsed++; } } double lat = Math.abs(location.getLatitude()); double lon = Math.abs(location.getLongitude()); String ns = (location.getLatitude() > 0) ? getString(R.string.value_N) : (location.getLatitude() < 0) ? getString(R.string.value_S) : ""; String ew = (location.getLongitude() > 0) ? getString(R.string.value_E) : (location.getLongitude() < 0) ? getString(R.string.value_W) : ""; String title = String.format("%.5f%s%s %.5f%s%s", lat, getString(R.string.unit_degree), ns, lon, getString(R.string.unit_degree), ew); String text = ""; if (location.hasAltitude()) { text = text + String.format("%.0f%s", location.getAltitude(), getString(R.string.unit_meter)); } if (location.hasSpeed()) { text = text + (text.equals("") ? "" : ", ") + String.format("%.0f%s", (location.getSpeed() * 3.6), getString(R.string.unit_km_h)); } if (location.hasAccuracy()) { text = text + (text.equals("") ? "" : ", ") + String.format("\u03b5 = %.0f%s", location.getAccuracy(), getString(R.string.unit_meter)); } text = text + (text.equals("") ? "" : ", ") + String.format("%d/%d", satsUsed, satsInView); text = text + (text.equals("") ? "" : ",\n") + String.format("TTFF %d s", status.getTimeToFirstFix() / 1000); mBuilder.setSmallIcon(R.drawable.ic_stat_notify_location); mBuilder.setContentTitle(title); mBuilder.setContentText(text); mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(text)); startForeground(ONGOING_NOTIFICATION, mBuilder.build()); } else { stopForeground(true); } }
From source file:a14n.geolocationdemo.MainActivity.java
private void requestLocationUpdates() { // Acquire a reference to the system Location Manager LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { JSONObject locationAsJson = new JSONObject(); try { locationAsJson.put("accuracy", location.getAccuracy()); locationAsJson.put("provider", location.getProvider()); locationAsJson.put("latitude", location.getLatitude()); locationAsJson.put("longitude", location.getLongitude()); locationAsJson.put("time", location.getTime()); } catch (JSONException e) { Log.e(TAG, "JSON exception", e); return; }//from w w w .ja v a2 s . c om flutterView.sendToFlutter("locations", locationAsJson.toString(), null); } public void onStatusChanged(String provider, int status, Bundle extras) { } public void onProviderEnabled(String provider) { } public void onProviderDisabled(String provider) { } }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); }