List of usage examples for android.location LocationManager NETWORK_PROVIDER
String NETWORK_PROVIDER
To view the source code for android.location LocationManager NETWORK_PROVIDER.
Click Source Link
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:com.crearo.gpslogger.GpsMainActivity.java
private void loadVersionSpecificProperties() { PackageInfo packageInfo;/*w w w. j a v a 2 s .com*/ try { packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0); int versionCode = packageInfo.versionCode; if (preferenceHelper.getLastVersionSeen() <= 71) { LOG.debug("preferenceHelper.getLastVersionSeen() " + preferenceHelper.getLastVersionSeen()); //Specifically disable passive provider... just once if (preferenceHelper.getChosenListeners().contains("passive")) { Set<String> listeners = new HashSet<>(); if (preferenceHelper.getChosenListeners().contains(LocationManager.GPS_PROVIDER)) { listeners.add(LocationManager.GPS_PROVIDER); } if (preferenceHelper.getChosenListeners().contains(LocationManager.NETWORK_PROVIDER)) { listeners.add(LocationManager.NETWORK_PROVIDER); } preferenceHelper.setChosenListeners(listeners); } } preferenceHelper.setLastVersionSeen(versionCode); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } }
From source file:com.mobicage.rogerthat.GetLocationActivity.java
private void getMyLocation() { mLocationProviderUpdates = mUseGPS.isChecked() ? LocationManager.GPS_PROVIDER : LocationManager.NETWORK_PROVIDER; mLocation = null;// w w w . ja va 2s. c o m try { mLocationManager.requestLocationUpdates(mLocationProviderUpdates, 0, 0, mLocationListener); } catch (SecurityException e) { L.bug(e); // Should never happen } mLocationQueryStart = System.currentTimeMillis(); mProgressDialog.setProgress(0); mProgressDialog.show(); mService.postDelayedOnUIHandler(mUpdateProgress, 100); }
From source file:org.y20k.trackbook.TrackerService.java
private void addWayPointToTrack() { // create new WayPoint WayPoint newWayPoint = null;/* ww w. j a v a 2 s.co m*/ // get number of previously tracked WayPoints int trackSize = mTrack.getWayPoints().size(); if (trackSize == 0) { // add first location to track newWayPoint = mTrack.addWayPoint(mCurrentBestLocation); } else { // get last WayPoint and compare it to current location Location lastWayPoint = mTrack.getWayPointLocation(trackSize - 1); // default value for average speed float averageSpeed = 0f; // compute average speed if new location come from network provider if (trackSize > 1 && mCurrentBestLocation.getProvider().equals(LocationManager.NETWORK_PROVIDER)) { Location firstWayPoint = mTrack.getWayPointLocation(0); float distance = firstWayPoint.distanceTo(lastWayPoint); long timeDifference = lastWayPoint.getElapsedRealtimeNanos() - firstWayPoint.getElapsedRealtimeNanos(); averageSpeed = distance / ((float) timeDifference / ONE_NANOSECOND); } if (LocationHelper.isNewWayPoint(lastWayPoint, mCurrentBestLocation, averageSpeed)) { // if new, add current best location to track newWayPoint = mTrack.addWayPoint(mCurrentBestLocation); } } // send local broadcast if new WayPoint added if (newWayPoint != null) { sendTrackUpdate(); } }
From source file:com.esri.cordova.geolocation.AdvancedGeolocation.java
private void validatePermissions() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Reference: Permission Groups https://developer.android.com/guide/topics/security/permissions.html#normal-dangerous // As of July 2016 - ACCESS_WIFI_STATE and ACCESS_NETWORK_STATE are not considered dangerous permissions Log.d(TAG, "validatePermissions()"); final int showRationale = _permissionsController.getShowRationale(); if (_permissionsController.getAppPermissions()) { startLocation();/*from w ww.jav a 2s .c o m*/ } // The user has said to never ask again about activating location services else if (showRationale == _permissionsController.DENIED_NOASK) { Log.w(TAG, ErrorMessages.LOCATION_SERVICES_DENIED_NOASK().message); sendCallback(PluginResult.Status.ERROR, JSONHelper.errorJSON(PROVIDER_PRIMARY, ErrorMessages.LOCATION_SERVICES_DENIED_NOASK())); } else if (showRationale == _permissionsController.ALLOW) { requestPermissions(); } else if (showRationale == _permissionsController.DENIED) { Log.w(TAG, "Rationale already shown, geolocation denied twice"); sendCallback(PluginResult.Status.ERROR, JSONHelper.errorJSON(PROVIDER_PRIMARY, ErrorMessages.LOCATION_SERVICES_DENIED())); } } else { final LocationManager _locationManager = (LocationManager) _cordovaActivity .getSystemService(Context.LOCATION_SERVICE); final boolean networkLocationEnabled = _locationManager .isProviderEnabled(LocationManager.NETWORK_PROVIDER); final boolean gpsEnabled = _locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); final boolean networkEnabled = isInternetConnected(_cordovaActivity.getApplicationContext()); // If warnings are disabled then skip initializing alert dialog fragments if (!_noWarn && (!networkLocationEnabled || !gpsEnabled || !networkEnabled)) { alertDialog(gpsEnabled, networkLocationEnabled, networkEnabled); } else { startLocation(); } } }
From source file:com.tonyandr.caminoguideoff.map.MapActivity.java
private void checkGPS() { LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE); if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER) && !lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { // Build the alert dialog AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Where are you?"); builder.setMessage("Please enable Location Services and GPS"); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override/* www. j av a 2 s . co m*/ public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); builder.setPositiveButton("Enable", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int i) { // Show location settings when the user acknowledges the alert dialog Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(intent); } }); Dialog alertDialog = builder.create(); alertDialog.setCanceledOnTouchOutside(false); alertDialog.show(); } }
From source file:de.uni.stuttgart.informatik.ToureNPlaner.UI.Activities.MapScreen.MapScreen.java
private void setupGPS(Bundle savedInstanceState, boolean isFirstStart) { Location loc = locManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); GeoPoint gpsGeoPoint = null;/*from w ww .jav a 2 s.c om*/ if (loc != null) { gpsGeoPoint = new GeoPoint(loc.getLatitude(), loc.getLongitude()); } // setting up LocationManager and set MapFocus on lastknown GPS-Location if (isFirstStart && gpsGeoPoint != null) { mapView.getController().setCenter(gpsGeoPoint); } gpsListener = new GpsListener(this, savedInstanceState, gpsGeoPoint); nodeOverlay = new NodeOverlay(this, session, gpsGeoPoint); }
From source file:ca.mudar.mtlaucasou.BaseMapFragment.java
/** * Initial map center animation on detected user location. If user is more * than minimum-distance from the city, center the map on Downtown. Also * defines the zoom.//from w w w.j av a 2 s . c o m */ protected void initialAnimateToPoint() { List<String> enabledProviders = mLocationManager.getProviders(true); double coordinates[] = Const.MAPS_DEFAULT_COORDINATES; final double lat = coordinates[0]; final double lng = coordinates[1]; Location userLocation = mAppHelper.getLocation(); if (userLocation != null) { /** * Center on app's user location. */ GeoPoint appGeoPoint = Helper.locationToGeoPoint(userLocation); mMapController.setCenter(appGeoPoint); } else { /** * Center on Downtown. */ GeoPoint cityCenter = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6)); mMapController.setCenter(cityCenter); } if ((mMapCenter == null) && enabledProviders.contains(LocationManager.NETWORK_PROVIDER)) { /** * Get user current location then display on map. */ mLocationOverlay.runOnFirstFix(new Runnable() { public void run() { GeoPoint userGeoPoint = mLocationOverlay.getMyLocation(); if (mListener != null) { mListener.OnMyLocationChanged(userGeoPoint); } /** * If user is very far from Montreal (> 25km) we center the * map on Downtown. */ float[] resultDistance = new float[1]; android.location.Location.distanceBetween(lat, lng, (userGeoPoint.getLatitudeE6() / 1E6), (userGeoPoint.getLongitudeE6() / 1E6), resultDistance); if (resultDistance[0] > Const.MAPS_MIN_DISTANCE) { userGeoPoint = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6)); } mMapCenter = userGeoPoint; mMapController.animateTo(userGeoPoint); } }); } else if (mMapCenter != null) { /** * The AppHelper knows the user location from a previous query, so * use the saved value. */ mMapController.setCenter(mMapCenter); } }
From source file:com.mobantica.DriverItRide.activities.ActivityLogin.java
private boolean valid() { if (edt_login_username.getText().toString().equals("")) { Toast.makeText(getApplicationContext(), getResources().getString(R.string.please_enter_username), Toast.LENGTH_SHORT).show(); return false; }/*from w w w . jav a 2s . c o m*/ if (edt_login_password.getText().toString().equals("")) { Toast.makeText(getApplicationContext(), getResources().getString(R.string.please_enter_password), Toast.LENGTH_SHORT).show(); return false; } if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { Toast.makeText(this, getResources().getString(R.string.need_location_permission_in_app_setting), Toast.LENGTH_SHORT).show(); return false; } if (ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { Toast.makeText(this, getResources().getString(R.string.need_phone_permission_in_app_setting), Toast.LENGTH_SHORT).show(); return false; } if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { Toast.makeText(this, getResources().getString(R.string.need_write_external_storage_permissionin_app_setting), Toast.LENGTH_SHORT).show(); return false; } LocationManager locationManager = (LocationManager) getApplicationContext() .getSystemService(Context.LOCATION_SERVICE); if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && !locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { Toast.makeText(getApplicationContext(), getResources().getString(R.string.please_enable_location), Toast.LENGTH_SHORT).show(); return false; } return true; }
From source file:com.ibm.mf.geofence.demo.MapsActivity.java
/** * Sets up the map if it is possible to do so (i.e., the Google Play services APK is correctly installed) and the map has not already been instantiated. *///w w w . j ava 2 s . c o m void setUpMapIfNeeded() { if (googleMap == null) { googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); log.debug("setUpMapIfNeeded() : googleMap = " + googleMap); if (googleMap != null) { LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); try { if (currentLocation == null) currentLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } catch (SecurityException e) { log.debug("missing permission to request get last location from NETWORK_PROVIDER"); } initGeofences(); // receive updates for th ecurrent location try { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 10f, new android.location.LocationListener() { @Override public void onLocationChanged(Location location) { currentLocation = location; refreshCurrentLocation(); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } }); } catch (SecurityException e) { log.debug("missing permission to request locations from NETWORK_PROVIDER"); } // set the map center and zoom level/bounds once it is loaded googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() { @Override public void onMapLoaded() { runOnUiThread(new Runnable() { @Override public void run() { List<MFGeofence> fences = geofenceHolder.getFences(); LatLng latlng = currentLocation != null ? new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()) : googleMap.getCameraPosition().target; Map<String, Object> map = (fences != null) && !fences.isEmpty() ? DemoUtils.computeBounds(fences, latlng) : DemoUtils.computeBounds(latlng, 0.0005, 0.0005); log.debug("setUpMapIfNeeded() : bounds map = " + map + ", fences = " + fences); LatLngBounds bounds = (LatLngBounds) map.get("bounds"); LatLng loc = (LatLng) map.get("center"); if (currentZoom >= 0f) { log.debug("setUpMapIfNeeded() setting zoom"); googleMap.moveCamera(CameraUpdateFactory.zoomTo(currentZoom)); } else { log.debug("setUpMapIfNeeded() setting bounds"); googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100)); } refreshCurrentLocation(loc.latitude, loc.longitude); } }); } }); // respond to taps on the fences labels googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() { @Override public boolean onMarkerClick(Marker marker) { if (mapMode != MODE_EDIT) { GeofenceInfo info = getGeofenceInfoForMarker(marker); log.debug(String.format("onMarkerClick(marker=%s) info=%s", marker, info)); EditGeofenceDialog dialog = new EditGeofenceDialog(); dialog.customInit(MapsActivity.this, EditGeofenceDialog.MODE_UPDATE_DELETE, info); dialog.show(getFragmentManager(), "geofences"); } return true; } }); } } }