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:kn.uni.gis.foxhunt.GameActivity.java
private void registerOnGPS() { locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!!!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(intent);// w ww . ja v a 2 s .co m } locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 500, 2f, this); if (SettingsContext.getInstance().isUseNetwork()) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 500, 2f, this); } }
From source file:be.brunoparmentier.openbikesharing.app.activities.MapActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_map); getActionBar().setDisplayHomeAsUpEnabled(true); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); stationsDataSource = new StationsDataSource(this); ArrayList<Station> stations = stationsDataSource.getStations(); map = (MapView) findViewById(R.id.mapView); stationMarkerInfoWindow = new StationMarkerInfoWindow(R.layout.bonuspack_bubble, map); /* handling map events */ MapEventsOverlay mapEventsOverlay = new MapEventsOverlay(this, this); map.getOverlays().add(0, mapEventsOverlay); /* markers list */ GridMarkerClusterer stationsMarkers = new GridMarkerClusterer(this); Drawable clusterIconD = getResources().getDrawable(R.drawable.marker_cluster); Bitmap clusterIcon = ((BitmapDrawable) clusterIconD).getBitmap(); map.getOverlays().add(stationsMarkers); stationsMarkers.setIcon(clusterIcon); stationsMarkers.setGridSize(100);/*from w w w .ja v a2 s. c o m*/ for (final Station station : stations) { stationsMarkers.add(createStationMarker(station)); } map.invalidate(); mapController = map.getController(); mapController.setZoom(16); map.setMultiTouchControls(true); map.setBuiltInZoomControls(true); map.setMinZoomLevel(3); /* map tile source */ String mapLayer = settings.getString("pref_map_layer", ""); switch (mapLayer) { case "mapnik": map.setTileSource(TileSourceFactory.MAPNIK); break; case "cyclemap": map.setTileSource(TileSourceFactory.CYCLEMAP); break; case "osmpublictransport": map.setTileSource(TileSourceFactory.PUBLIC_TRANSPORT); break; case "mapquestosm": map.setTileSource(TileSourceFactory.MAPQUESTOSM); break; default: map.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE); break; } GpsMyLocationProvider imlp = new GpsMyLocationProvider(this.getBaseContext()); imlp.setLocationUpdateMinDistance(1000); imlp.setLocationUpdateMinTime(60000); myLocationOverlay = new MyLocationNewOverlay(this.getBaseContext(), imlp, this.map); map.getOverlays().add(this.myLocationOverlay); myLocationOverlay.enableMyLocation(); try { LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); GeoPoint userLocation = new GeoPoint( locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)); mapController.animateTo(userLocation); } catch (NullPointerException e) { mapController.setZoom(13); double bikeNetworkLatitude = Double.longBitsToDouble(settings.getLong(PREF_KEY_NETWORK_LATITUDE, 0)); double bikeNetworkLongitude = Double.longBitsToDouble(settings.getLong(PREF_KEY_NETWORK_LONGITUDE, 0)); mapController.animateTo(new GeoPoint(bikeNetworkLatitude, bikeNetworkLongitude)); Toast.makeText(this, R.string.location_not_found, Toast.LENGTH_LONG).show(); } }
From source file:com.ibm.mf.geofence.demo.MapsActivity.java
@Override protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); if (savedInstanceState != null) { double[] loc = savedInstanceState.getDoubleArray("currentLocation"); if (loc != null) { currentLocation = new Location(LocationManager.NETWORK_PROVIDER); currentLocation.setLatitude(loc[0]); currentLocation.setLongitude(loc[1]); currentLocation.setTime(System.currentTimeMillis()); }//from ww w . j a v a2 s. c o m currentZoom = savedInstanceState.getFloat("zoom", -1f); //log.debug(String.format("restored currentLocation=%s; currentZoom=%f", currentLocation, currentZoom)); } }
From source file:org.koboc.collect.android.activities.GeoPointMapNotDraggableActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { mLocationCount = savedInstanceState.getInt(LOCATION_COUNT); }//from w w w . java 2s.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, GeoPointMapNotDraggableActivity.this); } if (mNetworkOn) { mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, GeoPointMapNotDraggableActivity.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:org.notfunnynerd.opencoinmap.MapActivity.java
private void initLocation() { // Get the location manager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); boolean enabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (!enabled) { Toast.makeText(this, getString(R.string.enable_location_service), Toast.LENGTH_LONG).show(); }/*from ww w . j a v a 2s .c o m*/ Criteria criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, false); }
From source file:cc.softwarefactory.lokki.android.fragments.MapViewFragment.java
private void checkLocationServiceStatus() { LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); boolean gps = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); boolean network = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (!gps && !network && !MainApplication.locationDisabledPromptShown) { promptLocationService();// w ww .ja va2 s.com MainApplication.locationDisabledPromptShown = true; } }
From source file:net.digitalphantom.app.weatherapp.WeatherActivity.java
private void getWeatherFromCurrentLocation() { if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION, }, GET_WEATHER_FROM_CURRENT_LOCATION); return;//from w w w . ja v a 2s .co m } // system's LocationManager final LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); boolean isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); boolean isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); Criteria locationCriteria = new Criteria(); if (isNetworkEnabled) { locationCriteria.setAccuracy(Criteria.ACCURACY_COARSE); } else if (isGPSEnabled) { locationCriteria.setAccuracy(Criteria.ACCURACY_FINE); } locationManager.requestSingleUpdate(locationCriteria, this, null); }
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); }/*from w w w . j av a 2 s. co 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.emuneee.nctrafficcams.ui.activities.MainActivity.java
public static Location getLocation(Context context) { Location location = null;/*from w w w . ja v a 2 s . com*/ if (mClient != null && mClient.isConnected()) { location = mClient.getLastLocation(); } if (location == null) { location = ((LocationManager) context.getSystemService(Context.LOCATION_SERVICE)) .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } return location; }
From source file:cd.education.data.collector.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 a v a 2 s . co 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) { 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(); } }); 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) { Collect.getInstance().getActivityLogger().logInstanceAction(this, "showLocation", "onClick"); mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mLatLng, 16)); } }); mShowLocation.setClickable(mMarker != null); }