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:fi.villel.foosquare.SearchActivity.java

private void updateLocation() {
    Location newLocation = null;//from ww  w. j a  va 2s  .  co  m
    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:fr.louisbl.cordova.gpslocation.CordovaGPSLocation.java

private void getLastLocation(JSONArray args, CallbackContext callbackContext) {
    int maximumAge;
    try {//from   www  . j av a  2  s.co m
        maximumAge = args.getInt(0);
    } catch (JSONException e) {
        e.printStackTrace();
        maximumAge = 0;
    }
    Location last = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    // Check if we can use lastKnownLocation to get a quick reading and use
    // less battery
    if (last != null && (System.currentTimeMillis() - last.getTime()) <= maximumAge) {
        PluginResult result = new PluginResult(PluginResult.Status.OK, returnLocationJSON(last));
        callbackContext.sendPluginResult(result);
    } else {
        getCurrentLocation(callbackContext, Integer.MAX_VALUE);
    }
}

From source file:net.evecom.androidecssp.activity.WelcomeActivity.java

/**
 * GIS/*from  w  w w .j  ava2 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:com.nadmm.airports.LocationListFragmentBase.java

protected void startLocationUpdates() {
    if (ContextCompat.checkSelfPermission(getActivity(),
            Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
                30 * DateUtils.SECOND_IN_MILLIS, 0.5f * GeoUtils.METERS_PER_STATUTE_MILE, this);

        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
        boolean useGps = prefs.getBoolean(PreferencesActivity.KEY_LOCATION_USE_GPS, false);
        if (useGps) {
            mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
                    30 * DateUtils.SECOND_IN_MILLIS, 0.5f * GeoUtils.METERS_PER_STATUTE_MILE, this);
        }//  w  w  w . jav  a  2 s .c o m
    } else if (!mPermissionDenied) {
        if (shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_FINE_LOCATION)) {
            Snackbar.make(getView(), "FlightIntel needs access to device's location.",
                    Snackbar.LENGTH_INDEFINITE).setAction(android.R.string.ok, new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            requestPermissions(new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                                    PERMISSION_REQUEST_FINE_LOCATION);
                        }
                    }).show();
        } else {
            requestPermissions(new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                    PERMISSION_REQUEST_FINE_LOCATION);
        }
    }
}

From source file:com.shadowmaps.example.GpsTestActivity.java

/** Called when the activity is first created. */
@Override/*  ww w. j a  v  a2s  . c om*/
public void onCreate(Bundle savedInstanceState) {
    setTheme(com.actionbarsherlock.R.style.Theme_Sherlock);
    super.onCreate(savedInstanceState);
    sInstance = this;

    // Set the default values from the XML file if this is the first
    // execution of the app
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    recording = false;
    mService = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    mProvider = mService.getProvider(LocationManager.GPS_PROVIDER);
    if (mProvider == null) {
        Log.e(TAG, "Unable to get GPS_PROVIDER");
        Toast.makeText(this, getString(R.string.gps_not_supported), Toast.LENGTH_SHORT).show();
        finish();
        return;
    }
    mService.addGpsStatusListener(this);

    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);

    // Request use of spinner for showing indeterminate progress, to show
    // the user something is going on during long-running operations
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    // If we have a large screen, show all the fragments in one layout
    if (GpsTestUtil.isLargeScreen(this)) {
        setContentView(R.layout.activity_main_large_screen);
        mIsLargeScreen = true;
    } else {
        setContentView(R.layout.activity_main);
    }

    initActionBar(savedInstanceState);

    SharedPreferences settings = Application.getPrefs();

    double tempMinTime = Double.valueOf(settings.getString(getString(R.string.pref_key_gps_min_time),
            getString(R.string.pref_gps_min_time_default_sec)));
    minTime = (long) (tempMinTime * SECONDS_TO_MILLISECONDS);
    minDistance = Float.valueOf(settings.getString(getString(R.string.pref_key_gps_min_distance),
            getString(R.string.pref_gps_min_distance_default_meters)));

    if (settings.getBoolean(getString(R.string.pref_key_auto_start_gps), true)) {
        gpsStart();
    }
    if (!isShadowServiceRunning(ShadowMapsService.class)) {
        final String STARTUP_EXTRA = "com.shadowmaps.example.start";
        Intent i = new Intent(this, ShadowMapsService.class);
        i.putExtra(STARTUP_EXTRA, true);
        startService(i);
        Log.v("SERVICE", "Starting ShadowService in activity onCreate");
    }
}

From source file:com.facebook.react.modules.location.LocationModule.java

/**
 * Start listening for location updates. These will be emitted via the
 * {@link RCTDeviceEventEmitter} as {@code geolocationDidChange} events.
 *
 * @param options map containing optional arguments: highAccuracy (boolean)
 *///from  www. j  ava2 s  .c o  m
@ReactMethod
public void startObserving(ReadableMap options) {
    if (LocationManager.GPS_PROVIDER.equals(mWatchedProvider)) {
        return;
    }
    LocationOptions locationOptions = LocationOptions.fromReactMap(options);

    try {
        LocationManager locationManager = (LocationManager) getReactApplicationContext()
                .getSystemService(Context.LOCATION_SERVICE);
        String provider = getValidProvider(locationManager, locationOptions.highAccuracy);
        if (provider == null) {
            emitError(PositionError.POSITION_UNAVAILABLE, "No location provider available.");
            return;
        }
        if (!provider.equals(mWatchedProvider)) {
            locationManager.removeUpdates(mLocationListener);
            locationManager.requestLocationUpdates(provider, 1000, locationOptions.distanceFilter,
                    mLocationListener);
        }
        mWatchedProvider = provider;
    } catch (SecurityException e) {
        throwLocationPermissionMissing(e);
    }
}

From source file:ca.ualberta.cs.cmput301w15t04team04project.MainActivity.java

/**
 * Called to do initial creation of a fragment.<br>
 * This is called after onAttach(Activity) and before
 * onCreateView(LayoutInflater, ViewGroup, Bundle).<br>
 * Note that this can be called while the fragment's activity is still in
 * the process of being created.<br>
 * As such, you can not rely on things like the activity's content view
 * hierarchy being initialized at this point.<br>
 * If you want to do work once the activity itself is created, see
 * onActivityCreated(Bundle).<br>//from   w  ww . ja v  a2  s .  co m
 * 
 * @param savedInstanceState
 *            If the fragment is being re-created from a previous saved
 *            state, this is the state.
 */
/*
 * (non-Javadoc)
 * 
 * @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // searchClaim.setVisible(true);
    setContentView(R.layout.activity_main);
    checker = new NetworkAvailabliltyCheck(getApplicationContext());
    user = SignInManager.loadFromFile(this);
    actionBar = getActionBar();
    actionBar.setTitle("My Local Claims");

    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if (checker.getNetworkAvailable()) {
        Toast.makeText(this, "net", Toast.LENGTH_SHORT).show();
        ClaimList claimList = MyLocalClaimListManager.loadClaimList(getApplicationContext(), user.getName());
        localController = new MyLocalClaimListController(claimList);
        localController.upload(getApplicationContext());
    }
    /*
     * if (location != null){ user.setHomelocation(location); TextView tv =
     * (TextView) findViewById(R.id.gpsHomeLocationTextView);
     * tv.setText("Lat: " + location.getLatitude() + "\nLong: " +
     * location.getLongitude()); }
     */
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, listener);

    initialisePaging();
}

From source file:br.liveo.ndrawer.ui.fragment.MainFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // TODO Auto-generated method stub      
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    mlblTime = (TextView) rootView.findViewById(R.id.lblTime);
    mTxtTime = (TextView) rootView.findViewById(R.id.txtTime);
    mlblSpeed = (TextView) rootView.findViewById(R.id.lblSpeed);
    mTxtSpeed = (TextView) rootView.findViewById(R.id.txtSpeed);
    mlblDistance = (TextView) rootView.findViewById(R.id.lblDistance);
    mTxtDistance = (TextView) rootView.findViewById(R.id.txtDistance);
    mlblTemp = (TextView) rootView.findViewById(R.id.lblTemp);
    mTxtTemp = (TextView) rootView.findViewById(R.id.txtTemp);
    mlblHum = (TextView) rootView.findViewById(R.id.lblHum);
    mTxtHum = (TextView) rootView.findViewById(R.id.txtHum);
    mBtnStart = (TextView) rootView.findViewById(R.id.btnStart);
    mlblMessage = (TextView) rootView.findViewById(R.id.lblMessage);

    mBtnStart.setOnClickListener(new View.OnClickListener() {
        @Override//from w  w  w.java 2 s  .c  o m
        public void onClick(View view) {
            if (mBtnStart.getText().equals("    ")) {
                Toast.makeText(getActivity(), "??? !", Toast.LENGTH_SHORT).show();
                updateEvent("RIDING_START");
                insertTrack();
                mStartTime = System.currentTimeMillis();

                MovementProfile.status = 1;

                jsonArr = new ArrayList<JSONObject>();

                mTimer.schedule(timerTask, 1000, 1000);
                mBtnStart.setText("    ");
            } else {
                Toast.makeText(getActivity(), "??? .", Toast.LENGTH_SHORT).show();
                updateEvent("RIDING_STOP");
                updateTrack();
                MovementProfile.status = 0;

                clearUI();
                mTimer.cancel();
                mBtnStart.setText("    ");
            }
        }
    });

    mLocationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
    if (!mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
        enableGPS();

    rootView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    return rootView;
}

From source file:it.unipr.informatica.autobusparma.MappaFragment.java

public void initLoc(LocationManager locMan) {

    locMan = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
    isGPSEnabled = locMan.isProviderEnabled(LocationManager.GPS_PROVIDER);

    if (!isGPSEnabled) {
        Toast.makeText(getActivity(), "GPS non attivo. \nVai nelle opzioni per attivarlo.", Toast.LENGTH_SHORT)
                .show();//w  ww.ja  va  2  s.c om
    }
    if (!isOnline()) {
        Toast.makeText(getActivity(), "Internet non attivo. \nVai nelle opzioni per attivarlo.",
                Toast.LENGTH_SHORT).show();
    }

}

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