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:com.tritop.androsense2.fragments.GpsFragment.java

public void resumeSensors() {
    mSensorManager.registerListener(this, defaultAccel, SensorManager.SENSOR_DELAY_UI);
    mSensorManager.registerListener(this, defaultMag, SensorManager.SENSOR_DELAY_UI);
    mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
    mLocationManager.addGpsStatusListener(this);
}

From source file:com.inloc.dr.StepService.java

@Override
public void onCreate() {
    Log.i(TAG, "[SERVICE] onCreate");
    super.onCreate();

    dtr = new DataRecorder();

    mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    showNotification();//from   ww  w  .ja v a  2s  . c  o m

    // Load settings
    mSettings = PreferenceManager.getDefaultSharedPreferences(this);
    mPedometerSettings = new PedometerSettings(mSettings);
    mState = getSharedPreferences("state", 0);

    mUtils = Utils.getInstance();
    mUtils.setService(this);

    acquireWakeLock();

    // Start detecting
    mStepDetector = new StepDetector();
    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
    mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);

    mTurnDetector = new TurnDetector();
    mTurnNotifier = new TurnNotifier();
    mTurnNotifier.addListener(mAngleListener);
    mTurnDetector.addTurnListener(mTurnNotifier);

    registerDetector();

    // Register our receiver for the ACTION_SCREEN_OFF action. This will make our receiver
    // code be called whenever the phone enters standby mode.
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
    registerReceiver(mReceiver, filter);

    mStepDisplayer = new StepDisplayer(mPedometerSettings, mUtils);
    mStepDisplayer.setSteps(mSteps = mState.getInt("steps", 0));
    mStepDisplayer.addListener(mStepListener);
    mStepDetector.addStepListener(mStepDisplayer);

    lSteps = mSteps;
    mConnManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    File mExternalRoot = android.os.Environment.getExternalStorageDirectory();
    mOutputDir = new File(mExternalRoot.getAbsolutePath() + "/datalogs/");
    // attempt to make output directory
    if (!mOutputDir.exists()) {
        mOutputDir.mkdirs();
    }
    // Used when debugging:
    // mStepBuzzer = new StepBuzzer(this);
    // mStepDetector.addStepListener(mStepBuzzer);

    // Start voice
    reloadSettings();

    // Tell the user we started.
    Toast.makeText(this, getText(R.string.started), Toast.LENGTH_SHORT).show();
}

From source file:com.kentli.cycletrack.RecordingService.java

public void startRecording(TripData trip) {
    this.state = STATE_RECORDING;
    this.trip = trip;

    curSpeed = maxSpeed = distanceTraveled = 0.0f;
    lastLocation = null;// w w  w .  j  a  v  a2 s. co  m

    // Add the notify bar and blinking light
    setNotification();

    // Start listening for GPS updates!
    lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);

    // Set up timer for bike bell
    if (timer != null) {
        timer.cancel();
        timer.purge();
    }
    timer = new Timer();
    timer.schedule(new TimerTask() {
        @Override
        public void run() {
            mHandler.post(mRemindUser);
        }
    }, BELL_FIRST_INTERVAL * 60000, BELL_NEXT_INTERVAL * 60000);
}

From source file:com.spoiledmilk.ibikecph.util.Util.java

public static Location locationFromCoordinates(double lat, double lng) {
    Location loc = new Location(LocationManager.GPS_PROVIDER);
    loc.setLatitude(lat);/*w  w w  .j  a  v a  2  s  . c o  m*/
    loc.setLongitude(lng);
    return loc;
}

From source file:com.android.deskclock.worldclock.CityAndTimeZoneLocator.java

private TZ resolveTimeZone() {
    BufferedReader br = null;/*from  w w w.  j  av a2  s .c o  m*/
    try {
        HttpClient client = new DefaultHttpClient();
        boolean gps = mLocation.getProvider().compareTo(LocationManager.GPS_PROVIDER) == 0;
        final URI uri = new URI(String.format(TIMEZONE_SERVICE_URI, String.valueOf(mLocation.getLatitude()),
                String.valueOf(mLocation.getLongitude()), String.valueOf(System.currentTimeMillis() / 1000L),
                String.valueOf(gps)));
        HttpGet request = new HttpGet();
        request.setURI(uri);
        HttpResponse response = client.execute(request);
        int status = response.getStatusLine().getStatusCode();
        if (status == HttpStatus.SC_OK) {
            // Read the response into XML
            br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
            return parseTimeZoneResponse(br);
        }
    } catch (URISyntaxException e) {
        Log.wtf(TAG, "Failed constructing the timezone request URI", e);
    } catch (IOException e) {
        Log.e(TAG, "Failed to retrieve timezone", e);
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                // Ignore
            }
        }
    }
    return null;
}

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  w w.  j av  a 2 s .com*/
        MainApplication.locationDisabledPromptShown = true;
    }
}

From source file:net.naonedbus.activity.map.layerloader.impl.BiclooMapLayer.java

@Override
public BasicItemizedOverlay getOverlay(final Context context, final int defaultItemId) {
    final BasicItemizedOverlay newItemizedOverlay;
    final EquipementManager equipementManager = EquipementManager.getInstance();
    final Equipement item = equipementManager.getSingle(context.getContentResolver(),
            Equipement.Type.TYPE_BICLOO, 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  w  w  .  j  a v  a  2 s.c om
        newItemizedOverlay = new BiclooItemizedOverlay(context.getResources());
    }
    return newItemizedOverlay;
}

From source file:havidarou.com.appgpsqr.MapsActivity.java

/**
 * Manipulates the map once available./*  w ww  .j  ava2  s. c o  m*/
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    // Add a marker to the new target
    if (latitude != 0.0 && longitude != 0.0) { // Checking if we have read a code
        LatLng target = new LatLng(latitude, longitude);
        mMap.addMarker(new MarkerOptions().position(target).title("New target!"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(target));
        mMap.setMyLocationEnabled(true);
        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) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return;
        }

        Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        longitude = location.getLongitude();
        latitude = location.getLatitude();
        // Call the route class to calculate a route
        route = new Route();
        // And the we draw it on the map
        route.drawRoute(mMap, MapsActivity.this, new LatLng(latitude, longitude), target, "es");
    }
}

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);
    }/*from   www  . j ava  2 s .  c  om*/

    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);

}

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);
    }//from   ww w  . java  2  s.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);

}