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:com.mpower.clientcollection.activities.GeoPointMapActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { mLocationCount = savedInstanceState.getInt(LOCATION_COUNT); }/* ww w. j av a 2s. c o m*/ requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.geopoint_layout); 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(); mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); mMap.setOnMarkerDragListener(this); 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); mMarker = mMap.addMarker(mMarkerOption); mRefreshLocation = false; // just show this position; don't change it... mMarker.setDraggable(mCaptureLocation); mZoomed = true; mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mLatLng, 16)); } mCancelLocation = (Button) findViewById(R.id.cancel_location); mCancelLocation.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ClientCollection.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) { ClientCollection.getInstance().getActivityLogger().logInstanceAction(this, "acceptLocation", "OK"); returnLocation(); } }); mMap.setOnMapLongClickListener(this); } 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) { ClientCollection.getInstance().getActivityLogger().logInstanceAction(this, "showLocation", "onClick"); mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mLatLng, 16)); } }); mShowLocation.setClickable(mMarker != null); }
From source file:android.zetterstrom.com.snow.fragments.SnowFragment.java
@RequiresPermission(permission.ACCESS_COARSE_LOCATION) private void findLocation() throws SecurityException { Location location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); SnowHelper.getForecast(location, new ForecastCallback() { @Override/*from w w w . j ava 2 s.c om*/ public void onForecastSuccess(Forecast forecast) { mForecast = forecast; showForecast(); } @Override public void onForecastError(@Nullable Throwable throwable) { showError(); } }); }
From source file:fi.villel.foosquare.SearchActivity.java
private void updateLocation() { Location newLocation = null;//from w ww . j av a2s . com Location gpsLocation = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); Location networkLocation = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (gpsLocation != null && networkLocation != null) { // Have both, choose the newer if (gpsLocation.getTime() >= networkLocation.getTime()) { newLocation = gpsLocation; } else { newLocation = networkLocation; } } else if (gpsLocation != null) { newLocation = gpsLocation; } else if (networkLocation != null) { newLocation = networkLocation; } if (newLocation != null) { double lat = newLocation.getLatitude(); double lon = newLocation.getLongitude(); mPresenter.setLocation(lat, lon); } }
From source file:jp.gr.java_conf.ya.shiobeforandroid3.UpdateTweetDrive.java
private final void init_location() { pref_app = PreferenceManager.getDefaultSharedPreferences(this); new Thread(new Runnable() { @Override//from w ww . ja va2 s .c o m public final void run() { try { final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setPowerRequirement(Criteria.POWER_HIGH); mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE); if (mLocationManager != null) { // final String provider = manager.getBestProvider(criteria, true); boolean provider_flag = false; final List<String> providers = mLocationManager.getProviders(true); for (final String provider : providers) { if ((provider.equals(LocationManager.GPS_PROVIDER)) || (provider.equals(LocationManager.NETWORK_PROVIDER))) { if (mLocationManager.isProviderEnabled(provider)) { provider_flag = true; } } WriteLog.write(UpdateTweetDrive.this, "requestLocationUpdates() provider: " + provider); final int pref_locationinfo_mintime = ListAdapter.getPrefInt(UpdateTweetDrive.this, "pref_locationinfo_mintime", "300000"); try { new Runnable() { @Override public final void run() { if (ContextCompat.checkSelfPermission(UpdateTweetDrive.this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { mLocationManager.requestLocationUpdates(provider, pref_locationinfo_mintime, 0, UpdateTweetDrive.this); } else { if (Build.VERSION.SDK_INT >= 23) requestPermissions( new String[] { android.Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_PERMISSION); } } }; } catch (final Exception e) { WriteLog.write(UpdateTweetDrive.this, e); } } if (startup_flag == true) { startup_flag = false; if (provider_flag == false) { toast(getString(R.string.open_location_source_settings)); try { startActivity(new Intent("android.settings.LOCATION_SOURCE_SETTINGS")); } catch (final ActivityNotFoundException e) { WriteLog.write(UpdateTweetDrive.this, e); } catch (final Exception e) { WriteLog.write(UpdateTweetDrive.this, e); } } } } } catch (final IllegalArgumentException e) { WriteLog.write(UpdateTweetDrive.this, e); } catch (final RuntimeException e) { WriteLog.write(UpdateTweetDrive.this, e); } } }).start(); }
From source file:com.berniesanders.fieldthebern.controllers.LocationController.java
@TargetApi(23) private Location getLocation() throws LocationUnavailableException { if (Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(context, ACCESS_FINE_LOCATION) != PERMISSION_GRANTED && ContextCompat.checkSelfPermission(context, ACCESS_COARSE_LOCATION) != PERMISSION_GRANTED) { // TODO: Consider calling: ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) Timber.e("location permission error"); throw new LocationUnavailableException("location permission error"); }// w w w .j a v a 2s . co m Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (location == null) { throw new LocationUnavailableException("location was null"); } return location; }
From source file:org.klnusbaum.udj.PlayerListFragment.java
public void onStart() { super.onStart(); if (searchType == SearchType.LOCATION_SEARCH) { lm = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); List<String> providers = lm.getProviders(false); if (providers.contains(LocationManager.GPS_PROVIDER)) { lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 50, this); if (lastKnown == null) { lastKnown = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); }/*from w w w . jav a 2s. c o m*/ } if (providers.contains(LocationManager.NETWORK_PROVIDER)) { lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 50, this); if (lastKnown == null) { lastKnown = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } } } }
From source file:net.evecom.androidecssp.activity.WelcomeActivity.java
/** * GIS// ww w . j a va2 s . co m */ private void manageGis() { // mMyLocation = new MyOverlay(this, null); // locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { toast("", 0); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, mMyLocation); } else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 1, mMyLocation); toast("", 0); } else { toast("", 0); } }
From source file:au.id.tedp.mapdroid.Picker.java
public Location getLastLocation(Context ctx) { LocationManager locmgr = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE); Location l = locmgr.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (l != null) return l; return locmgr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); }
From source file:com.ptts.fragments.BusLocation.java
@Override protected void onStart() { super.onStart(); if (locationManager != null) { boolean gpsIsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); boolean networkIsEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (gpsIsEnabled) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000L, 10F, this); } else if (networkIsEnabled) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000L, 10F, this); } else {//from w w w . ja v a 2 s. c o m //Show an error dialog that GPS is disabled... Log.i("NO GPS", "GPS is off"); } } }
From source file:org.streetpacman.DMBoard.java
/** * Registers to receive location updates from the GPS location provider and * sensor updated from the compass./* w w w. ja v a 2 s . c o m*/ */ void registerLocationAndSensorListeners() { if (locationManager != null) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); try { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000 * 60 * 5 /* minTime */, 0 /* minDist */, locationListener); } catch (RuntimeException e) { // If anything at all goes wrong with getting a cell location do // not // abort. Cell location is not essential to this app. Log.w(DMConstants.TAG, "Could not register network location listener."); } } if (sensorManager == null) { return; } Sensor compass = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); if (compass == null) { return; } Log.d(DMConstants.TAG, "DM: Now registering sensor listeners."); sensorManager.registerListener(sensorListener, compass, SensorManager.SENSOR_DELAY_UI); }