Tabnine Logo
LocationManager.requestLocationUpdates
Code IndexAdd Tabnine to your IDE (free)

How to use
requestLocationUpdates
method
in
android.location.LocationManager

Best Java code snippets using android.location.LocationManager.requestLocationUpdates (Showing top 20 results out of 846)

Refine searchRefine arrow

  • LocationManager.getLastKnownLocation
  • LocationManager.isProviderEnabled
  • LocationManager.removeUpdates
  • Location.getLongitude
  • Location.getLatitude
  • Context.getSystemService
origin: stackoverflow.com

 LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L,1.0f, this);
boolean isGPS = locationManager.isProviderEnabled (LocationManager.GPS_PROVIDER);
origin: stackoverflow.com

Location location = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(location != null && location.getTime() > Calendar.getInstance().getTimeInMillis() - 2 * 60 * 1000) {
  mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
if (location != null) {
  Log.v("Location Changed", location.getLatitude() + " and " + location.getLongitude());
  mLocationManager.removeUpdates(this);
origin: stackoverflow.com

  lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
try{gps_enabled=lm.isProviderEnabled(LocationManager.GPS_PROVIDER);}catch(Exception ex){}
try{network_enabled=lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);}catch(Exception ex){}
  lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListenerGps);
if(network_enabled)
  lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListenerNetwork);
timer1=new Timer();
timer1.schedule(new GetLastLocation(), 20000);
  timer1.cancel();
  locationResult.gotLocation(location);
  lm.removeUpdates(this);
  lm.removeUpdates(locationListenerNetwork);
  timer1.cancel();
  locationResult.gotLocation(location);
  lm.removeUpdates(this);
  lm.removeUpdates(locationListenerGps);
     gps_loc=lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
   if(network_enabled)
     net_loc=lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
origin: stackoverflow.com

  locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
  if(gpsProvider != null)
    locationManager.requestLocationUpdates(gpsProvider.getName(), 0, 10, this);
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000 * 60 * 5, 0, this);
public void deactivate()
  locationManager.removeUpdates(this);
origin: googlecodelabs/android-lifecycles

void addLocationListener() {
  // Note: Use the Fused Location Provider from Google Play Services instead.
  // https://developers.google.com/android/reference/com/google/android/gms/location/FusedLocationProviderApi
  mLocationManager =
      (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
  mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mListener);
  Log.d("BoundLocationMgr", "Listener added");
  // Force an update with the last location, if available.
  Location lastLocation = mLocationManager.getLastKnownLocation(
      LocationManager.GPS_PROVIDER);
  if (lastLocation != null) {
    mListener.onLocationChanged(lastLocation);
  }
}
origin: tazimete/android-app-food-delivery-system

public void setLocationManagerAndListener(){
  this.locationListener = new SmartSendLocationListener(this.ctx);
  this.locationManager = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE);
  isGPSProviderEnable = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
  isNetworkProviderEnable = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
  if(isGPSProviderEnable){
    this.locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTimeForUpdateLocastion, minDistanceForUpdateLocation, locationListener);
  }else if(isNetworkProviderEnable){
    this.locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, minTimeForUpdateLocastion, minDistanceForUpdateLocation, locationListener);
  }
}
origin: stackoverflow.com

 private void _getLocation() {
  // Get the location manager
  LocationManager locationManager = (LocationManager) 
      getSystemService(LOCATION_SERVICE);
  Criteria criteria = new Criteria();
  String bestProvider = locationManager.getBestProvider(criteria, false);
  Location location = locationManager.getLastKnownLocation(bestProvider);
  LocationListener loc_listener = new LocationListener() {

    public void onLocationChanged(Location l) {}

    public void onProviderEnabled(String p) {}

    public void onProviderDisabled(String p) {}

    public void onStatusChanged(String p, int status, Bundle extras) {}
  };
  locationManager
      .requestLocationUpdates(bestProvider, 0, 0, loc_listener);
  location = locationManager.getLastKnownLocation(bestProvider);
  try {
    lat = location.getLatitude();
    lon = location.getLongitude();
  } catch (NullPointerException e) {
    lat = -1.0;
    lon = -1.0;
  }
}
origin: stackoverflow.com

this.isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
this.isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
        MIN_TIME_BW_UPDATES,
        MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
    if (locationManager != null)   {
      location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
      updateCoordinates();
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
        MIN_TIME_BW_UPDATES,
        MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
      location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
      updateCoordinates();
origin: Shimingli/PerformanceOptimizationForAndroid

      @Override
      public void onLocationChanged(Location location) {
        // thread is not runable, msg ignore, state:TIMED_WAITING, 这里的线程有可能ANR
        if (location != null) {
          double lat = location.getLatitude();//获取纬度
          double lng = location.getLongitude();//获取经度
          System.out.println("shiming   lat+" + lat);
          System.out.println("shiming   lng+" + lng);
          String name = Thread.currentThread().getName();
          mCount++;
          System.out.println("当前线程的位置name---"+name+"i==="+mCount);
          mTv_location.setText("位置信息是2s变动的,可以设置,我是第"+mCount+"次变动的--->"+"\n\r"+"lat===="+lat+"      lng----->"+lng);
        }
        if (mLocationManager!=null) {
          mLocationManager.removeUpdates(this);
          if (mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
            mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 2000, 1000, mLlistener);
          }else {
            mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 1000, mLlistener);
          }
//                     TODO: 2018/5/3  这里在报错了,我把他注释掉
//                mLocationManager.setTestProviderEnabled(mProvider, false);//   java.lang.IllegalArgumentException: Provider "network" unknown
        }
      }

origin: facebook/facebook-android-sdk

private Location getFreshLocation() throws ScannerException {
  freshLocation = null;
  HandlerThread handlerThread = new HandlerThread("LocationScanner");
  try {
    handlerThread.start();
    for (String provider : enabledProviders) {
      locationManager.requestLocationUpdates(
          provider,
          MIN_TIME_BETWEEN_UPDATES,
          MIN_DISTANCE_BETWEEN_UPDATES,
          this,
          handlerThread.getLooper());
    }
    try {
      synchronized (scanLock) {
        scanLock.wait(params.getLocationRequestTimeoutMs());
      }
    } catch (Exception e) {
      // ignore
    }
  } finally {
    locationManager.removeUpdates(this);
    handlerThread.quit();
  }
  if (freshLocation == null) {
    throw new ScannerException(ScannerException.Type.TIMEOUT);
  }
  return freshLocation;
}
origin: stackoverflow.com

super.onCreate();
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
sendBroadcastMessage(locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER));
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME, MIN_DISTANCE,
    new LocationListener() {
      @Override
origin: stackoverflow.com

  public void onLocationChanged(Location location) {
    double latitude = location.getLatitude();
    double longitude = location.getLongitude();
    double speed = location.getSpeed(); //spedd in meter/minute
    speed = (speed*3600)/1000;      // speed in km/minute               Toast.makeText(GraphViews.this, "Current speed:" + location.getSpeed(),Toast.LENGTH_SHORT).show();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
origin: stackoverflow.com

try {
  locationManager = (LocationManager) mContext
      .getSystemService(LOCATION_SERVICE);
      .isProviderEnabled(LocationManager.GPS_PROVIDER);
      .isProviderEnabled(LocationManager.NETWORK_PROVIDER);
    this.canGetLocation = true;
    if (isNetworkEnabled) {
      locationManager.requestLocationUpdates(
          LocationManager.NETWORK_PROVIDER,
          MIN_TIME_BW_UPDATES,
      if (locationManager != null) {
        location = locationManager
            .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        if (location != null) {
          latitude = location.getLatitude();
        locationManager.requestLocationUpdates(
            LocationManager.GPS_PROVIDER,
            MIN_TIME_BW_UPDATES,
  locationManager.removeUpdates(GPSTracker.this);
origin: stackoverflow.com

 public void FindLocation(Context context){
  final LocationManager locationManager (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
  LocationListener locationListener = new LocationListener(){
    public void onLocationChanged(Location location){
      updateLocation(location);
      locationManager.removeUpdates(this);
    }
    public void onStatusChanged(String provider, int status, Bundle extras) {}
    public void onProviderEnabled(String provider) {}
    public void onProviderDisabled(String provider) {}
  };
  locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
}
origin: googlecodelabs/android-lifecycles

@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
void addLocationListener() {
  // Note: Use the Fused Location Provider from Google Play Services instead.
  // https://developers.google.com/android/reference/com/google/android/gms/location/FusedLocationProviderApi
  mLocationManager =
      (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
  mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mListener);
  Log.d("BoundLocationMgr", "Listener added");
  // Force an update with the last location, if available.
  Location lastLocation = mLocationManager.getLastKnownLocation(
      LocationManager.GPS_PROVIDER);
  if (lastLocation != null) {
    mListener.onLocationChanged(lastLocation);
  }
}
origin: openbmap/radiocells-scanner-android

public boolean getLocation(final Context context, final LocationResult result) {
  //I use LocationResult callback class to pass location value from CurrentLocationHelper to user code.
  mLocationResult = result;
  if (mLocationManager ==  null)
    mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
  //exceptions will be thrown if provider is not permitted.
  try {
    mGpsEnabled = mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
  } catch (final Exception ex) {
  }
  try {
    mNetworkEnabled = mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
  } catch(final Exception ex){
  }
  //don't start listeners if no provider is enabled
  if (!mGpsEnabled && !mNetworkEnabled)
    return false;
  if (mGpsEnabled)
    mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListenerGps);
  if (mNetworkEnabled)
    mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListenerNetwork);
  mTimer = new Timer();
  mTimer.schedule(new GetLastLocation(), 20000);
  return true;
}
origin: stackoverflow.com

boolean gpsIsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean networkIsEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
  locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000L, 10F, this);
  locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000L, 10F, this);
locationManager.removeUpdates(this);
mMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(location.getLatitude(), location.getLongitude())));
origin: stackoverflow.com

  Location location = locationManager.getLastKnownLocation(provider);
protected void onResume() {
  super.onResume();
  locationManager.requestLocationUpdates(provider, 400, 1, this);
protected void onPause() {
  super.onPause();
  locationManager.removeUpdates(this);
origin: stackoverflow.com

gps_enabled = (Boolean) myLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
myLocationManager.requestLocationUpdates("network", 0, 0, networkLocationListener);
myLocationManager.requestLocationUpdates("gps", 0, 0, gpsLocationListener);
myLocationManager.addGpsStatusListener(gpsStatusListener);
   Location location = lm.getLastKnownLocation(strLocationProvider);
   if(location != null){
    return location;
origin: stackoverflow.com

  if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
protected void onStart() {
  super.onStart();
  locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
      0, this);
  locationManager.removeUpdates(this);
  super.onStop();
android.locationLocationManagerrequestLocationUpdates

Popular methods of LocationManager

  • isProviderEnabled
  • removeUpdates
  • getLastKnownLocation
  • getBestProvider
  • getAllProviders
  • getProviders
  • addGpsStatusListener
  • removeGpsStatusListener
  • getGpsStatus
  • requestSingleUpdate
  • addTestProvider
  • setTestProviderEnabled
  • addTestProvider,
  • setTestProviderEnabled,
  • setTestProviderLocation,
  • removeTestProvider,
  • getProvider,
  • clearTestProviderEnabled,
  • setTestProviderStatus,
  • addNmeaListener,
  • removeNmeaListener

Popular in Java

  • Making http post requests using okhttp
  • setScale (BigDecimal)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • setRequestProperty (URLConnection)
  • Table (com.google.common.collect)
    A collection that associates an ordered pair of keys, called a row key and a column key, with a sing
  • Socket (java.net)
    Provides a client-side TCP socket.
  • Arrays (java.util)
    This class contains various methods for manipulating arrays (such as sorting and searching). This cl
  • Iterator (java.util)
    An iterator over a sequence of objects, such as a collection.If a collection has been changed since
  • BlockingQueue (java.util.concurrent)
    A java.util.Queue that additionally supports operations that wait for the queue to become non-empty
  • JTable (javax.swing)
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now