Android. Definition of coordinates



  • How do you define the coordinates upon request?

    For example, now I find the coordinates as follows:

    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000 * 10, 10, locationListener);
            locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000 * 10, 10, locationListener);
    

    private LocationListener locationListener = new LocationListener() {

    @Override
    public void onLocationChanged(Location location) {}
    
    @Override
    public void onProviderDisabled(String provider) {}
    
    @Override
    public void onProviderEnabled(String provider) {}
    
    @Override
    public void onStatusChanged(String provider, int status, Bundle extras){}
    

    };

    But there's one nail here, and he'll call a subscription to an event - locationListener, depending on the change of my coordinates or time.

    I don't need that. I want to get the coordinates one time and work with them again, if necessary.

    If time is given = 0 and meters = 0, it will simply update the coordinates as often as possible.



  • Starting with API 9, there's an excellent method. requestSingleUpdate(...) Ooh. LocationManager for such purposes.
    Either pay attention. getLastKnownLocation(...)




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2