List of usage examples for android.location LocationManager GPS_PROVIDER
String GPS_PROVIDER
To view the source code for android.location LocationManager GPS_PROVIDER.
Click Source Link
From source file:com.boundlessgeo.spatialconnect.scutilities.LocationHelper.java
/** * Enable GPS updates. (start listening) */// w w w .j a v a 2 s . c o m public void enableGps() { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_BETWEEN_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this); }
From source file:com.nextgis.maplibui.fragment.CompassFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (null == getParentFragment()) { setRetainInstance(true);//from www .j av a2 s. c o m } // reference to vibrator service mDeclination = 0; mVibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE); mSensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); if (!PermissionUtil.hasPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) || !PermissionUtil.hasPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION)) return; if (mCurrentLocation == null) { LocationManager locationManager = (LocationManager) getActivity() .getSystemService(Context.LOCATION_SERVICE); mCurrentLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (mCurrentLocation == null) { mCurrentLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } } if (mCurrentLocation != null) mDeclination = getDeclination(mCurrentLocation, System.currentTimeMillis()); }
From source file:com.asc.msigeosystems.prism4d.YGPS.java
@Override public void onProviderEnabled(String provider) { if (LocationManager.GPS_PROVIDER.equals(provider)) { setGpsStatus(); } }
From source file:com.example.vedantn.algaeestimator.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Set values for the main spinner calcMethodSpinner = (Spinner) findViewById(R.id.calcMethodSpinner); ArrayAdapter adapterCalcMethod = ArrayAdapter.createFromResource(this, R.array.calcMethod, android.R.layout.simple_spinner_dropdown_item); calcMethodSpinner.setAdapter(adapterCalcMethod); calcMethodSpinner.setOnItemSelectedListener(this); spinnerDepth = (Spinner) findViewById(R.id.spinnerDepth); spinnerDepth.setOnItemSelectedListener(this); spinnerStemp = (Spinner) findViewById(R.id.spinnerStemp); spinnerStemp.setOnItemSelectedListener(this); spinnerBotTemp = (Spinner) findViewById(R.id.spinnerBotTemp); spinnerBotTemp.setOnItemSelectedListener(this); spinnerSD = (Spinner) findViewById(R.id.spinnerSD); spinnerSD.setOnItemSelectedListener(this); //Get all user inputs tbValueOfAlgal = (EditText) findViewById(R.id.tbValueOfAlgal); tbPbott = (EditText) findViewById(R.id.tbPbott); tbDepth = (EditText) findViewById(R.id.tbDepth); tbStemp = (EditText) findViewById(R.id.tbStemp); tbBotTemp = (EditText) findViewById(R.id.tbBotTemp); tbSD = (EditText) findViewById(R.id.tbSD); tbDO = (EditText) findViewById(R.id.tbDO); tbLakeDescription = (EditText) findViewById(R.id.tbLakeDescription); lblLocation = (TextView) findViewById(R.id.lblLocation); //Get GPS coordinates locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationListener = new LocationListener() { @Override/*from w ww . j ava2 s . c o m*/ //This methods is called every time the GPS location changes public void onLocationChanged(Location location) { if (location != null) { userLat = location.getLatitude(); userLon = location.getLongitude(); //Toast.makeText(MainActivity.this,"Location Changed",Toast.LENGTH_LONG).show(); lblLocation.setText("Current Location\n" + userLat + "\n" + userLon); } } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } }; //Get location updated after 60000 milliseconds or 5 meters. locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 5, locationListener); }
From source file:net.naonedbus.activity.map.layerloader.impl.ParkingMapLayer.java
@Override public BasicItemizedOverlay getOverlay(final Context context, final int defaultItemId) { final BasicItemizedOverlay newItemizedOverlay; final Equipement item = equipementManager.getSingle(context.getContentResolver(), defaultItemId); if (item != null) { final Location location = new Location(LocationManager.GPS_PROVIDER); location.setLatitude(item.getLatitude()); location.setLongitude(item.getLongitude()); newItemizedOverlay = getOverlay(context, location); } else {//from w ww . j av a2s . com newItemizedOverlay = new ParkingItemizedOverlay(context.getResources()); } return newItemizedOverlay; }
From source file:com.asc.msigeosystems.prism4d.YGPS.java
@Override public void onStatusChanged(String provider, int status, Bundle extras) { if (!LocationManager.GPS_PROVIDER.equals(provider)) { return;/*w ww. j av a 2s . c o m*/ } setGpsStatus(); }
From source file:com.facebook.react.modules.location.LocationModule.java
@Nullable private String getValidProvider(LocationManager locationManager, boolean highAccuracy) { String provider = highAccuracy ? LocationManager.GPS_PROVIDER : LocationManager.NETWORK_PROVIDER; if (!locationManager.isProviderEnabled(provider)) { provider = provider.equals(LocationManager.GPS_PROVIDER) ? LocationManager.NETWORK_PROVIDER : LocationManager.GPS_PROVIDER; if (!locationManager.isProviderEnabled(provider)) { return null; }/*w ww.j a v a 2 s. c o m*/ } // If it's an enabled provider, but we don't have permissions, ignore it int finePermission = ContextCompat.checkSelfPermission(getReactApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION); if (provider.equals(LocationManager.GPS_PROVIDER) && finePermission != PackageManager.PERMISSION_GRANTED) { return null; } return provider; }
From source file:com.projectattitude.projectattitude.Activities.MapActivity.java
/** * Handles everything/*from w w w. j a v a 2 s .c o m*/ * @param map */ @Override public void onMapReady(GoogleMap map) { mMap = map; LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); if (ContextCompat.checkSelfPermission(MapActivity.this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(MapActivity.this, new String[] { android.Manifest.permission.ACCESS_FINE_LOCATION }, MY_PERMISSION_ACCESS_COARSE_LOCATION); } /** * http://stackoverflow.com/questions/18425141/android-google-maps-api-v2-zoom-to-current-location 4/1/2017 4:20pm */ Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false)); if (location != null) { map.animateCamera(CameraUpdateFactory .newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 13)); CameraPosition cameraPosition = new CameraPosition.Builder() .target(new LatLng(location.getLatitude(), location.getLongitude())) // Sets the center of the map to location user .zoom(15) // Sets the zoom .bearing(0) // Sets the orientation of the camera to east .tilt(40) // Sets the tilt of the camera to 30 degrees .build(); // Creates a CameraPosition from the builder map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); } enableMyLocation(); //couldn't get ColorMap to work, so made one for the meantime HashMap<String, BitmapDescriptor> hm = new HashMap<String, BitmapDescriptor>(); hm.put("Anger", BitmapDescriptorFactory.fromResource(R.drawable.ic_anger_colour_36px));//defaultMarker(356)); hm.put("Confusion", BitmapDescriptorFactory.fromResource(R.drawable.ic_confusion_colour_36px));//defaultMarker(19)); hm.put("Disgust", BitmapDescriptorFactory.fromResource(R.drawable.ic_disgust_colour_36px));//defaultMarker(65)); hm.put("Fear", BitmapDescriptorFactory.fromResource(R.drawable.ic_fear_colour_36px));//defaultMarker(42)); hm.put("Happiness", BitmapDescriptorFactory.fromResource(R.drawable.ic_happiness_colour_36px));//defaultMarker(160)); hm.put("Sadness", BitmapDescriptorFactory.fromResource(R.drawable.ic_sadness_colour_36px));//defaultMarker(60)); hm.put("Shame", BitmapDescriptorFactory.fromResource(R.drawable.ic_shame_colour_36px));//defaultMarker(200)); hm.put("Surprise", BitmapDescriptorFactory.fromResource(R.drawable.ic_surprise_colour_36px));//defaultMarker(22)); //Taken from https://developers.google.com/maps/documentation/android-api/marker //On March 21st at 17:53 map.setOnInfoWindowClickListener(this); if (getIntent().hasExtra("users")) { ArrayList<User> users = (ArrayList<User>) getIntent().getSerializableExtra("users"); GPSTracker gps = new GPSTracker(MapActivity.this); //LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); //LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { latitude = Math.round(gps.getLatitude() * 10000d) / 10000d; longitude = Math.round(gps.getLongitude() * 10000d) / 10000d; if (latitude != 0 & longitude != 0) { Toast.makeText(MapActivity.this, "Found your location", Toast.LENGTH_LONG).show(); Log.d("Distance", "Current Location: " + latitude + " " + longitude); for (int i = 0; i < users.size(); i++) { Mood mood = users.get(i).getFirstMood(); // if(mood.getLatitude()!= null && mood.getLongitude() != null) { if (mood != null) { Double returned = calculateDistance(latitude, longitude, mood.getLatitude(), mood.getLongitude()); returned = returned / 1000; Log.d("Distance", "Current Distance: " + returned); Log.d("Distance", "Current comparison to: " + users.get(i).getUserName() + " " + mood.getEmotionState()); if (returned < 5) { map.addMarker(new MarkerOptions() .position(new LatLng(mood.getLatitude(), mood.getLongitude())) .title(mood.getMaker()).snippet(mood.getEmotionState()) .icon(hm.get(mood.getEmotionState()))).setTag(mood); } } } } else { Toast.makeText(MapActivity.this, "Could not find your location, please try again!", Toast.LENGTH_LONG).show(); } } else { Toast.makeText(MapActivity.this, "Please turn on GPS for locations!", Toast.LENGTH_LONG).show(); } } else if (getIntent().hasExtra("user")) { ArrayList<Mood> userMoodList = (ArrayList<Mood>) getIntent().getSerializableExtra("user"); for (int i = 0; i < userMoodList.size(); i++) { //TODO this will get EVERY mood from the user, which could be too many Mood mood = userMoodList.get(i); if (mood.getLongitude() == 0 && mood.getLatitude() == 0) { Log.d("MapMoods", "Mood: " + mood.getEmotionState() + "not mapped"); } else { map.addMarker(new MarkerOptions().position(new LatLng(mood.getLatitude(), mood.getLongitude())) .title(mood.getMaker()).snippet(mood.getEmotionState()) .icon(hm.get(mood.getEmotionState()))).setTag(mood); } } } else { Toast.makeText(MapActivity.this, "MIts Fucked, nothing go passed", Toast.LENGTH_LONG).show(); } }
From source file:com.wirelessmoves.cl.MainActivity.java
@SuppressWarnings("deprecation") @Override// w w w.j a v a 2 s. com public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); /* If saved variable state exists from last run, recover it */ if (savedInstanceState != null) { NumberOfSignalStrengthUpdates = savedInstanceState.getLong("NumberOfSignalStrengthUpdates"); LastCellId = savedInstanceState.getLong("LastCellId"); NumberOfCellChanges = savedInstanceState.getLong("NumberOfCellChanges"); LastLacId = savedInstanceState.getLong("LastLacId"); NumberOfLacChanges = savedInstanceState.getLong("NumberOfLacChanges"); PreviousCells = savedInstanceState.getLongArray("PreviousCells"); PreviousCellsIndex = savedInstanceState.getInt("PreviousCellsIndex"); NumberOfUniqueCellChanges = savedInstanceState.getLong("NumberOfUniqueCellChanges"); outputDebugInfo = savedInstanceState.getBoolean("outputDebugInfo"); CurrentLocationLong = savedInstanceState.getDouble("CurrentLocationLong"); CurrentLocationLat = savedInstanceState.getDouble("CurrentLocationLat"); /* attempt to restore the previous gps location information object */ PrevLocation = (Location) getLastNonConfigurationInstance(); } else { /* Initialize PreviousCells Array to defined values */ for (int x = 0; x < PreviousCells.length; x++) PreviousCells[x] = 0; } /* Get a handle to the telephony manager service */ /* A listener will be installed in the object from the onResume() method */ MyListener = new MyPhoneStateListener(); Tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); /* get a handle to the power manager and set a wake lock so the screen saver * is not activated after a timeout */ PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "DoNotDimScreen"); /* Get a handle to the location system for getting GPS information */ locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); gpsListener = new myLocationListener(); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, gpsListener); }
From source file:com.sitewhere.android.example.ExampleFragment.java
/** * Only schedule SiteWhere reporting thread once we have a connection to the server. *///from w ww.j a va2 s .com public void startDeviceMonitoring() { Log.d(TAG, "Starting device monitoring."); getActivity().runOnUiThread(new Runnable() { @Override public void run() { // Start location updates. boolean locationStarted = false; locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { Log.d(TAG, "No permissions for location. Requesting permissions from user."); requestPermissions(new String[] { Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION }, LOCATION_REQUEST_CODE); return; } if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ExampleFragment.this); locationStarted = true; Log.d(TAG, "Started monitoring locations via GPS provider."); } else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, ExampleFragment.this); locationStarted = true; Log.d(TAG, "Started monitoring locations via network provider."); } else { locationStarted = false; Log.d(TAG, "No location provider available. Will not monitor location."); } // Start accelerometer updates. boolean accelerometerStarted = false; sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); if (sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null) { rotationVector = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); sensorManager.registerListener(ExampleFragment.this, rotationVector, SensorManager.SENSOR_DELAY_NORMAL); accelerometerStarted = true; Log.d(TAG, "Started monitoring accelerometer."); } else { Toast.makeText(getActivity().getApplicationContext(), "Unable to start accelerometer updates. No accelerometer provided", Toast.LENGTH_LONG); accelerometerStarted = false; Log.d(TAG, "Unable to monitor accelerometer."); } // Send alerts to SiteWhere. SiteWhereMessageClient messageClient = SiteWhereMessageClient.getInstance(); try { if (locationStarted) messageClient.sendDeviceAlert(messageClient.getUniqueDeviceId(), "location.started", "Started to read location data.", null); } catch (SiteWhereMessagingException ex) { Log.e(TAG, "Unable to send location.started alert to SiteWhere."); } try { if (accelerometerStarted) messageClient.sendDeviceAlert(messageClient.getUniqueDeviceId(), "accelerometer.started", "Started to read accelerometer data.", null); } catch (SiteWhereMessagingException e) { Log.e(TAG, "Unable to send accelerometer.started alert to SiteWhere."); } if (scheduler != null) { scheduler.shutdownNow(); } scheduler = Executors.newSingleThreadScheduledExecutor(); scheduler.scheduleAtFixedRate(new SiteWhereDataReporter(), SEND_INTERVAL_IN_SECONDS, SEND_INTERVAL_IN_SECONDS, TimeUnit.SECONDS); Log.d(TAG, "Set up scheduler for monitoring."); } }); }