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.airg.android.permission.sample.DangerousFragment.java

@SuppressWarnings("ResourceType")
private void onLocationPermissionGranted() {
    latitude.setText(R.string.loading);/* ww w .j  a va 2s .  c  o  m*/
    longitude.setText(R.string.loading);

    final Activity activity = getActivity();
    gps = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
    updateLocation(gps.getLastKnownLocation(LocationManager.NETWORK_PROVIDER));
    gps.requestSingleUpdate(LocationManager.GPS_PROVIDER, this, null);
}

From source file:de.uvwxy.whereami.ActivityMain.java

private void alertIfProviderIsNotEnabled() {
    boolean provEnabledGPS = LocationReader.isEnabled(this, LocationManager.GPS_PROVIDER);
    boolean provEnabledWiFi = LocationReader.isEnabled(this, LocationManager.NETWORK_PROVIDER);

    SharedPreferences pref = IntentTools.getSettings(this, SETTINGS);
    boolean setEnabledGPS = pref.getBoolean(SETTINGS_USE_GPS, SETTINGS_USE_GPS_DEF);
    boolean setEnabledWiFi = pref.getBoolean(SETTINGS_USE_WIFI, SETTINGS_USE_WIFI_DEF);
    pref = null;/*w w  w.  jav a2  s  . c  om*/

    boolean showAlert = true;
    String locationProviderStateMessage = getString(R.string.waiting_for_fix);
    if ((!provEnabledGPS && setEnabledGPS) && (!provEnabledWiFi && setEnabledWiFi)) {
        locationProviderStateMessage = getString(R.string.app_load_warn_no_gps_no_wifi);
    } else if (!provEnabledGPS && setEnabledGPS) {
        locationProviderStateMessage = getString(R.string.app_load_warn_no_gps);
    } else if (!provEnabledWiFi && setEnabledWiFi) {
        locationProviderStateMessage = getString(R.string.app_load_warn_no_wifi);
    } else {
        showAlert = false;
    }

    if (showAlert) {
        AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
        alertDialog.setNegativeButton(R.string.ok, null);
        alertDialog.setMessage(locationProviderStateMessage);
        alertDialog.setTitle(R.string.enable_provider);
        alertDialog.show();
    }
}

From source file:org.klnusbaum.udj.EventListFragment.java

public void onStart() {
    super.onStart();
    lm = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
    List<String> providers = lm.getProviders(false);
    if (providers.contains(LocationManager.GPS_PROVIDER)) {
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 50, this);
        if (lastKnown == null) {
            lastKnown = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        }//w w  w. ja v  a  2 s.c  o m
    }
    if (providers.contains(LocationManager.NETWORK_PROVIDER)) {
        lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 50, this);
        if (lastKnown == null) {
            lastKnown = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        }
    }
    if (lastSearch == null) {
        lastSearch = new LocationEventSearch(lastKnown);
    }
}

From source file:com.android.gpstest.GpsTestActivity.java

private boolean sendExtraCommand(String command) {
    return mService.sendExtraCommand(LocationManager.GPS_PROVIDER, command, null);
}

From source file:csic.ceab.movelab.beepath.FixGet.java

public void onStart(Intent intent, int startId) {

    if (fixInProgress == false) {
        fixInProgress = true;//from  www. ja  va2  s  .c om
        stopFilter = new IntentFilter(Util.createInternalMessage(Util.MESSAGE_STOP_FIXGET, context));
        stopReceiver = new StopReceiver();
        registerReceiver(stopReceiver, stopFilter);

        announceFixStarted();

        if (PropertyHolder.useSensorACCELEROMETER())
            startService(new Intent(FixGet.this, SensorGetAccelerometer.class));

        if (PropertyHolder.useSensorMAGNETIC_FIELD())
            startService(new Intent(FixGet.this, SensorGetMagneticField.class));

        if (PropertyHolder.useSensorORIENTATION())
            startService(new Intent(FixGet.this, SensorGetOrientation.class));

        if (PropertyHolder.useSensorGRAVITY())
            startService(new Intent(FixGet.this, SensorGetGravity.class));

        if (PropertyHolder.useSensorLINEAR_ACCELERATION())
            startService(new Intent(FixGet.this, SensorGetLinear_Acceleration.class));

        if (PropertyHolder.useSensorGYROSCOPE())
            startService(new Intent(FixGet.this, SensorGetGyroscope.class));

        // stopListening = null;
        bestLocation = null;

        if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {

            if (Util.flushGPSFlag == true) {

                clearGPS();
                injectNewXTRA();
                Util.flushGPSFlag = false;
            }

            locationListener1 = new mLocationListener();
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener1);

            // mGpsStatusListener= new GpsStatusListener();
            // locationManager.addGpsStatusListener(mGpsStatusListener);

        }

        if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
            locationListener2 = new mLocationListener();
            locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener2);

        }

    }
}

From source file:net.evecom.androidecssp.gps.ResourceItemizedOverlayActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    initData();//from w w  w  .  j a  v a  2 s.c  o  m
    /** 2.2 ***/
    setContentView(R.layout.itemized_resource);
    /** 2.2 ***/
    mMapView = (MapView) findViewById(R.id.itemized_mapview);
    mMapView.setBuiltInZoomControls(true);
    // Overlay
    // mMapView.setDrawOverlayWhenZooming(true);
    mController = mMapView.getController();
    mCon = this;
    // 
    List<Overlay> list = mMapView.getOverlays();
    centerGpsPoint = new GeoPoint((int) (26.031846613632812 * 1E6), (int) (119.4909095748828 * 1E6));
    mController.setCenter(centerGpsPoint);
    sp = instance.getSharedPreferences("GPS", instance.MODE_PRIVATE);
    myLocation = new MyGpsLocationOverlay(this, mMapView,
            new MyGpsLocationOverlay.MyGpsLocationOverlayinterface() {
                @Override
                public void onLocationChanged(Location location, GeoPoint geoPoint) {
                    Editor editor = sp.edit();
                    editor.putString("latitude", "" + location.getLatitude());
                    editor.putString("longitude", "" + location.getLongitude());
                    editor.commit();
                    String strLog = String.format(":\r\n" + ":%f\r\n" + ":%f",
                            location.getLongitude(), location.getLatitude());
                    Toast.makeText(instance, strLog, Toast.LENGTH_SHORT).show();
                    if (!ismanuallocation) {
                        centerGpsPoint = geoPoint;
                    }
                }
            });
    myLocation.enableCompass();
    myLocation.enableMyLocation();
    list.add(myLocation);
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, myLocation);
    } else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 1, myLocation);
    }

    list.add(new ManualLocationOverlay(this, new ManualLocationOverlay.ManualMapOnCilck() {
        @Override
        public void mapclick(GeoPoint point, MapView mapView) {
            ismanuallocation = true;
            centerGpsPoint = point;
        }
    }));// 

    // initAroundDialog();
    initOtherView();

}

From source file:com.pansapiens.occyd.Search.java

public void searchByTag(String[] taglist) {
    String tags = joinString(taglist, ",");

    final URL url;
    UrlFetch fetcher;// w  ww.  j a v  a 2  s .c om
    /*
    for (int i = 0; i < taglist.length; i++) {
       tags += taglist[0];
    }
    */

    try {
        String BASEURL = getString(R.string.occyd_server);
        if (distance == 0) {
            url = new URL(BASEURL + "/v1/posts/get?tag=" + tags + "&format=json");
            fetcher = new UrlFetch(url, handle_result);
        } else {
            Location here = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            double lat = here.getLatitude();
            double lon = here.getLongitude();

            String current_ll = String.format("%f,%f", lat, lon);
            url = new URL(BASEURL + "/v1/posts/get?tag=" + tags + "&radius=" + distance + "&near=" + current_ll
                    + "&format=json");

            Toast.makeText(Search.this, url.toString(), Toast.LENGTH_LONG).show();

            fetcher = new UrlFetch(url, handle_result);
        }

        // run http fetch in a thread, with 
        // 'searching' dialog
        final Thread tr = new Thread() {
            @Override
            public void run() {
                handle_result.post(mDisplaySearching);
                UrlFetch fetcher = new UrlFetch(url, handle_result);
                fetcher.fetch();
                handle_result.post(mDismissSearching);
            }
        };
        tr.start();

    } catch (MalformedURLException e) {
        Toast.makeText(Search.this, "FAIL: Malformed URL.", Toast.LENGTH_LONG).show();
    } catch (IOException e) {
        Toast.makeText(Search.this, "FAIL: http fetch failed.", Toast.LENGTH_LONG).show();
    }
}

From source file:com.asc.msigeosystems.prism4d.YGPS.java

@Override
public void onProviderDisabled(String provider) {
    if (LocationManager.GPS_PROVIDER.equals(provider)) {
        setGpsStatus();
    }
}

From source file:com.luke.lukef.lukeapp.tools.LukeUtils.java

/**
 * Checks the current GPS status, if GPS is not enabled then calls
 * {@link LukeUtils#alertDialogBuilder(Context, String, String)} to create a prompt for the user
 * to enable GPS./*w ww .  j  av a 2  s . co  m*/
 *
 * @param context Context, needed to create the alert.
 * @return <b>true</b> if the GPS is enabled, <b>false</b> if it's not.
 */
public static boolean checkGpsStatus(Context context) {
    final LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        alertDialogBuilder(context, noGps, android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        return false;
    } else {
        return true;
    }
}

From source file:com.hit.jj.mapshow.RoutingActivity.java

/**
 * ??// w  w  w  . j  ava 2  s.  c om
 */
private void init() {
    manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    //???
    initialEnv();
    initialTts();

    if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        buildAlertMessageNoGps();
    }
    // Retrieve the map and initial extent from XML layout
    map = (MapView) findViewById(R.id.map);
    // Add tiled layer to MapView
    tileLayer = new ArcGISDynamicMapServiceLayer(
            "http://58.199.250.101:6080/arcgis/rest/services/xmut/map/MapServer");
    map.addLayer(tileLayer);
    mFeatureLayer = new ArcGISFeatureLayer(
            "http://58.199.250.101:6080/arcgis/rest/services/xm/path1/FeatureServer/0",
            ArcGISFeatureLayer.MODE.SELECTION);
    map.addLayer(mFeatureLayer);
    Callout mapCallout = map.getCallout();
    mapCallout.hide();
    // Add the route graphic layer (shows the full route)
    routeLayer = new GraphicsLayer();
    map.addLayer(routeLayer);
    mFeatureLayer.getFields();
    graphicsLayer = new GraphicsLayer();
    map.addLayer(graphicsLayer);
    MyOnSingleTapListener listener = new MyOnSingleTapListener(this);
    map.setOnSingleTapListener(listener);
    try {
        mRouteTask = RouteTask.createOnlineRouteTask(
                "http://58.199.250.101:6080/arcgis/rest/services/xmut/path2/NAServer/path", null);

    } catch (Exception e1) {
        e1.printStackTrace();
    }
    // Add the hidden segments layer (for highlighting route segments)
    hiddenSegmentsLayer = new GraphicsLayer();
    map.addLayer(hiddenSegmentsLayer);

    // Make the segmentHider symbol "invisible"
    segmentHider.setAlpha(1);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    img_cancel = (ImageView) findViewById(R.id.iv_cancel);
    img_currLocation = (ImageView) findViewById(R.id.iv_myLocation);
    img_getDirections = (ImageView) findViewById(R.id.iv_getDirections);
    mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    img_speak = (ImageView) findViewById(R.id.iv_speak);
    img_showDirections = (ImageView) findViewById(R.id.direction);
    // Get the location display manager and start reading location. Don't
    // auto-pan
    // to center our position
    ldm = map.getLocationDisplayManager();
    ldm.setLocationListener(new MyLocationListener());
    ldm.start();
    ldm.setAutoPanMode(AutoPanMode.LOCATION);

    // Set the directionsLabel with initial instructions.
    directionsLabel = (TextView) findViewById(R.id.directionsLabel);
    directionsLabel.setText(getString(R.string.route_label));
}