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.crowdpp.nagisa.crowdpp2.util.LocationTracker.java

public Location getLocation() {
    try {/*from   w  ww .ja  v a 2s  . c o m*/
        locationManager = (LocationManager) mContext.getSystemService(Context.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;
            // if GPS Enabled get lat/long using GPS Services
            if (isGPSEnabled) {
                if (location == null) {
                    if (ContextCompat.checkSelfPermission(mContext,
                            android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                        Log.i("LocationTracker", "Permission Denied!");
                    }
                    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES,
                            MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                    Log.i("LocationTracker", "GPS Enabled");
                    if (locationManager != null) {
                        location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                        if (location != null) {
                            latitude = location.getLatitude();
                            longitude = location.getLongitude();
                        }
                        if (latitude == 0.0 || longitude == 0.0) {//GPS is not available
                            locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
                                    MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                            Log.i("LocationTracker", "Network Enabled");
                            if (locationManager != null) {
                                location = locationManager
                                        .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                                if (location != null) {
                                    latitude = location.getLatitude();
                                    longitude = location.getLongitude();
                                }
                            }
                        }
                    }
                }
            } else {
                if (isNetworkEnabled) {
                    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
                            MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                    Log.i("LocationTracker", "Network Enabled");
                    if (locationManager != null) {
                        location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                        if (location != null) {
                            latitude = location.getLatitude();
                            longitude = location.getLongitude();
                        }
                    }
                }
            }
        }

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

    return location;
}

From source file:com.yammy.meter.map.MainMapBengkel.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.isvo_map_bengkel);
    this.jarak = (TextView) this.findViewById(R.id.map_bengkel_length);

    int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
    if (result != ConnectionResult.SUCCESS) {
        GooglePlayServicesUtil.getErrorDialog(result, MainMapBengkel.this, 1).show();
    } else {/*w w  w .j a  v  a  2 s . c o  m*/
        map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
        GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(getBaseContext());

        map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        map.setIndoorEnabled(false);
        bundle = getIntent().getExtras();
        try {
            data_pos = new LatLng(Double.parseDouble(bundle.getString("lat")),
                    Double.parseDouble(bundle.getString("long")));
            Toast.makeText(getBaseContext(), bundle.getString("lat") + "," + bundle.getString("long"),
                    Toast.LENGTH_LONG).show();
        } catch (NumberFormatException e) {
            Toast.makeText(getBaseContext(), "Mencari lokasi saat ini", Toast.LENGTH_SHORT).show();
        }

        /**
         * mulai edan dari ini ke bawah
         */
        LocationManager service = (LocationManager) this.getSystemService(LOCATION_SERVICE);
        boolean enabledGPS = service.isProviderEnabled(LocationManager.GPS_PROVIDER);
        if (!enabledGPS) {
            Toast.makeText(this, "GPS tidak ditemukan", Toast.LENGTH_LONG).show();
            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivity(intent);
        }
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 0, this);
        if (location != null && location.getTime() > Calendar.getInstance().getTimeInMillis() - 2 * 60 * 1000) {
            Toast.makeText(getApplicationContext(),
                    "Current Location : " + location.getLatitude() + "," + location.getLongitude(),
                    Toast.LENGTH_LONG).show();
            drawMarker(location);
        } else {
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
        }
    }
}

From source file:com.qasp.diego.arsp.LocalizacaoGPSService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (checkPermission(getApplicationContext()))
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, INTERVALO_TEMPO, INTERVALO_DISTANCIA, ll);
    ultimamedicaoGPS = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    Long = ultimamedicaoGPS.getLongitude();
    Lat = ultimamedicaoGPS.getLatitude();
    return Service.START_NOT_STICKY;
}

From source file:com.garrocho.MapActivity.java

private Location getLastBestLocation() {
    Location locationGPS = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    return locationGPS;
}

From source file:ch.luethi.skylinestracker.PositionService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    skyLinesTrackingWriter = null;//from www.j a v a 2s  .com
    initConnectionStatus();
    ipAddress = prefs.getIpAddress();
    senderThread = new HandlerThread("SenderThread");
    senderThread.start();
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, prefs.getTrackingInterval() * 1000, 0,
            this, senderThread.getLooper());
    return START_STICKY;
}

From source file:com.mobicage.rogerthat.GetLocationActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case TURNING_ON_GPS:
        if (mLocationManager != null)
            mUseGPS.setChecked(mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER));
        break;/*  w w w. jav a2s  .c o m*/
    case LOCATION_REQUEST_CODE:
        if (data != null && data.getBooleanExtra(MapDetailActivity.VERIFIED, false)) {
            Intent intent = getIntent();
            intent.putExtra(MapDetailActivity.LATITUDE, mLocation.getLatitude());
            intent.putExtra(MapDetailActivity.LONGITUDE, mLocation.getLongitude());
            setResult(RESULT_OK, intent);
            finish();
        }
        break;
    }
}

From source file:com.simadanesh.isatis.CommonPlace.java

public void StartLocationManager(Context context) {
    if (locationManager == null) {
        locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);

        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
    }//from   ww  w.  j ava 2s  .  co m
}

From source file:com.mbapps.alibi.services.TrackingService.java

/**
 * Gets the latest known location and adds it to the database
 *///  w  ww  .  j a  va2s  .c  o m
private void addTracking() {
    Location lastKnownLocation = this.locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if (lastKnownLocation != null) {
        Log.v(TAG, lastKnownLocation.getLatitude() + " " + lastKnownLocation.getLongitude());
        this.trackingsKeeper
                .addTracking(new Tracking(Calendar.getInstance().getTimeInMillis(), lastKnownLocation));
    }
}

From source file:ca.lightseed.winston.WinstonService.java

/**
 * onStart begins the visible lifetime for the activity.
 * This method performs a permissions check: the app requires either coarse or fine
 * location data permissions to have any function.
 * @param intent//  www .  ja va 2  s  .  co  m
 * @param startId
 */
@Override
public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);
    locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);

    if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
            || checkSelfPermission(
                    Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 5, listener);
    }

    Toast.makeText(this, "Started Winston tracking service", Toast.LENGTH_SHORT).show();
}

From source file:com.app.swaedes.swaedes.GPSTracker.java

public Location getLocation() {
    if (Build.VERSION.SDK_INT >= 23
            && ContextCompat.checkSelfPermission(mContext,
                    android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ContextCompat.checkSelfPermission(mContext,
                    android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return null;
    } else {//w  w  w. j  a v  a2 s . c om
        try {
            locationManager = (LocationManager) mContext.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) {
                            latitude = location.getLatitude();
                            longitude = 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) {
                                latitude = location.getLatitude();
                                longitude = location.getLongitude();
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return location;
    }
}