Example usage for android.location LocationManager GPS_PROVIDER

List of usage examples for android.location LocationManager GPS_PROVIDER

Introduction

In this page you can find the example usage for android.location LocationManager GPS_PROVIDER.

Prototype

String GPS_PROVIDER

To view the source code for android.location LocationManager GPS_PROVIDER.

Click Source Link

Document

Name of the GPS location provider.

Usage

From source file:android.melbournehistorymap.MapsActivity.java

@Override
public void onRestart() {
    LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    String locationProvider = LocationManager.GPS_PROVIDER;
    Location mLastLocation = locationManager.getLastKnownLocation(locationProvider);

    double lat = mLastLocation.getLatitude();
    double lng = mLastLocation.getLongitude();
    final int radius;
    int zoom;//from   w  w  w  .jav  a 2s.co m

    //build current location
    LatLng currentLocation = new LatLng(lat, lng);

    if (MELBOURNE.contains(currentLocation)) {
        mMap.getUiSettings().setMyLocationButtonEnabled(true);
        zoom = 17;
    } else {
        mMap.getUiSettings().setMyLocationButtonEnabled(false);
        lat = -37.81161508043379;
        lng = 144.9647320434451;
        zoom = 15;
        currentLocation = new LatLng(lat, lng);
    }

    CameraPosition cameraPosition = new CameraPosition.Builder().target(currentLocation) // Sets the center of the map to location user
            .zoom(zoom) // Sets the zoom
            .bearing(0) // Sets the orientation of the camera to east
            .tilt(25) // Sets the tilt of the camera to 30 degrees
            .build(); // Creates a CameraPosition from the builder

    //Animate user to map location, if in Melbourne or outside of Melbourne bounds
    mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition),
            new GoogleMap.CancelableCallback() {
                @Override
                public void onFinish() {
                    updateMap();
                }

                @Override
                public void onCancel() {

                }
            });

    updateMap();
    super.onRestart();
}

From source file:com.SecUpwN.AIMSICD.service.AimsicdService.java

public Location lastKnownLocation() {
    Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if (location == null || (location.getLatitude() == 0.0 && location.getLongitude() == 0.0)) {
        location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        if (location == null || (location.getLatitude() == 0.0 && location.getLongitude() == 0.0)) {

        }//  w  w w  .  ja v  a 2 s .c o  m
    }

    return location;
}

From source file:com.corporatetaxi.TaxiArrived_Acitivity.java

public Location getLocation() {
    try {//  w w w  .j  a  va  2s  .co  m
        map.setMyLocationEnabled(true);
        locationManager = (LocationManager) this.getSystemService(LOCATION_SERVICE);

        // getting GPS status
        isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

        // getting network status
        isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

        if (!isGPSEnabled && !isNetworkEnabled) {
            // no network provider is enabled
        } else {
            this.canGetLocation = true;
            // First get location from Network Provider
            if (isNetworkEnabled) {
                locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME_BW_UPDATES,
                        MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                Log.d("Network", "Network");
                if (locationManager != null) {
                    location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                    if (location != null) {
                        lat = location.getLatitude();
                        lon = location.getLongitude();
                    }
                }
            }
            // if GPS Enabled get lat/long using GPS Services
            if (isGPSEnabled) {
                if (location == null) {
                    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES,
                            MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                    Log.d("GPS Enabled", "GPS Enabled");
                    if (locationManager != null) {
                        location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                        if (location != null) {
                            lat = location.getLatitude();
                            lon = location.getLongitude();
                        }
                    }
                }
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return location;
}

From source file:com.vonglasow.michael.satstat.ui.MapSectionFragment.java

/**
 * Updates the list of styles to use for the location providers.
 * //from w  w  w .  jav  a 2  s  .  co m
 * This method updates the internal list of styles to use for displaying
 * locations on the map, assigning a style to each location provider.
 * Styles that are defined in {@link SharedPreferences} are preserved. If
 * none are defined, the GPS location provider is assigned the red style
 * and the network location provider is assigned the blue style. The
 * passive location provider is not assigned a style, as it does not send
 * any locations of its own. Other location providers are assigned one of
 * the following styles: green, orange, purple. If there are more location
 * providers than styles, the same style (including red and blue) can be
 * assigned to multiple providers. The mapping is written to 
 * SharedPreferences so that it will be preserved even as available
 * location providers change.
 */
public void updateLocationProviderStyles() {
    //FIXME: move code into assignLocationProviderStyle and use that
    List<String> allProviders = mainActivity.locationManager.getAllProviders();
    allProviders.remove(LocationManager.PASSIVE_PROVIDER);
    if (allProviders.contains(LocationManager.GPS_PROVIDER)) {
        providerStyles.put(LocationManager.GPS_PROVIDER, mainActivity.mSharedPreferences.getString(
                Const.KEY_PREF_LOC_PROV_STYLE + LocationManager.GPS_PROVIDER, Const.LOCATION_PROVIDER_RED));
        mAvailableProviderStyles.remove(Const.LOCATION_PROVIDER_RED);
        allProviders.remove(LocationManager.GPS_PROVIDER);
    }
    if (allProviders.contains(LocationManager.NETWORK_PROVIDER)) {
        providerStyles.put(LocationManager.NETWORK_PROVIDER,
                mainActivity.mSharedPreferences.getString(
                        Const.KEY_PREF_LOC_PROV_STYLE + LocationManager.NETWORK_PROVIDER,
                        Const.LOCATION_PROVIDER_BLUE));
        mAvailableProviderStyles.remove(Const.LOCATION_PROVIDER_BLUE);
        allProviders.remove(LocationManager.NETWORK_PROVIDER);
    }
    for (String prov : allProviders) {
        if (mAvailableProviderStyles.isEmpty())
            mAvailableProviderStyles.addAll(Arrays.asList(Const.LOCATION_PROVIDER_STYLES));
        providerStyles.put(prov, mainActivity.mSharedPreferences.getString(Const.KEY_PREF_LOC_PROV_STYLE + prov,
                mAvailableProviderStyles.get(0)));
        mAvailableProviderStyles.remove(providerStyles.get(prov));
    }
    ;
    SharedPreferences.Editor spEditor = mainActivity.mSharedPreferences.edit();
    for (String prov : providerStyles.keySet())
        spEditor.putString(Const.KEY_PREF_LOC_PROV_STYLE + prov, providerStyles.get(prov));
    spEditor.commit();
}

From source file:com.example.angel.parkpanda.MainActivity.java

public Location moveMyPosCamera() {

    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this,
                    Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return null;
    }//from  ww  w.  jav  a 2  s  .  c om
    Location myLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);

    if (myLocation == null) {
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_COARSE);
        String provider = lm.getBestProvider(criteria, true);
        myLocation = lm.getLastKnownLocation(provider);
    }
    return myLocation;
}

From source file:br.com.bioscada.apps.biotracks.services.TrackRecordingService.java

/**
 * Resumes current track./*from  w  w  w .j av a  2  s.  c  o  m*/
 */
private void resumeCurrentTrack() {
    if (!isRecording() || !isPaused()) {
        Log.d(TAG, "Ignore resumeCurrentTrack. Not recording or not paused.");
        return;
    }

    // Update shared preferences
    recordingTrackPaused = false;
    PreferencesUtils.setBoolean(this, R.string.recording_track_paused_key, false);

    // Update database
    Track track = myTracksProviderUtils.getTrack(recordingTrackId);
    if (track != null) {
        Location resume = new Location(LocationManager.GPS_PROVIDER);
        resume.setLongitude(0);
        resume.setLatitude(RESUME_LATITUDE);
        resume.setTime(System.currentTimeMillis());
        insertLocation(track, resume, null);
    }

    startRecording(false);
}

From source file:com.dragon4.owo.ar_trace.ARCore.MixView.java

public void onProviderDisabled(String provider) {
    if (locationMgr != null)
        isGpsEnabled = locationMgr.isProviderEnabled(LocationManager.GPS_PROVIDER);
}

From source file:com.dragon4.owo.ar_trace.ARCore.MixView.java

public void onProviderEnabled(String provider) {
    if (locationMgr != null)
        isGpsEnabled = locationMgr.isProviderEnabled(LocationManager.GPS_PROVIDER);
}

From source file:com.lcl.thumbweather.MainActivity.java

void getCityByLocation() {
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_CONTACTS)) {
            // Explanation not needed, since user requests this himself

        } else {/*from  w ww  . j av a 2  s . c o  m*/
            ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                    MY_PERMISSIONS_ACCESS_FINE_LOCATION);
        }

    } else {
        progressDialog.setMessage(getString(R.string.getting_location));
        progressDialog.setCanceledOnTouchOutside(false);
        progressDialog.show();
        LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
    }
}

From source file:com.SecUpwN.AIMSICD.service.AimsicdService.java

/**
 * Cell Information Tracking and database logging
 *
 * @param track Enable/Disable tracking// www  .j ava 2  s .  c o  m
 */
public void setCellTracking(boolean track) {
    if (track) {
        tm.listen(mCellSignalListener,
                PhoneStateListener.LISTEN_CELL_LOCATION | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
                        | PhoneStateListener.LISTEN_DATA_ACTIVITY
                        | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
        if (lm != null) {
            mLocationListener = new MyLocationListener();
            Log.i(TAG, "LocationManager already existed");
            lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_MIN_UPDATE_TIME,
                    GPS_MIN_UPDATE_DISTANCE, mLocationListener);
        } else {
            Log.i(TAG, "LocationManager did not exist");
            lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
            if (lm != null) {
                if (lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                    Log.i(TAG, "LocationManager created");
                    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_MIN_UPDATE_TIME,
                            GPS_MIN_UPDATE_DISTANCE, mLocationListener);
                }
            }
        }
        Helpers.msgShort(this, "Tracking cell information");
        mTrackingCell = true;
    } else {
        tm.listen(mCellSignalListener, PhoneStateListener.LISTEN_NONE);
        lm.removeUpdates(mLocationListener);
        mDevice.mCell.setLon(0.0);
        mDevice.mCell.setLat(0.0);
        mTrackingCell = false;
        mDevice.setCellInfo("[0,0]|nn|nn|");
        Helpers.msgShort(this, "Stopped tracking cell information");
    }
    setNotification();
}