Home > Back-end >  Android requestLocationUpdates interval callback is not accurate
Android requestLocationUpdates interval callback is not accurate

Time:11-29

Use the locationManager. RequestLocationUpdates interval parameter is 1000 (1 second), why the on-board equipment callback is 2 seconds at a time?
Phone verification once a second didn't found the problem...

 
The import android. The annotation. SuppressLint;
The import android. The content. The Context;
The import android. The location. The location;
The import android. Location. LocationListener;
The import android. Location. LocationManager;
The import android. OS. Bundle;
The import android. Util. Log;

@ SuppressLint (" MissingPermission ")
Public class GpsLocationManager {

Private static final String TAG="GpsLocationManager";
Public double latitude;
Public double longitude;
Private LocationManager LocationManager.

@ SuppressLint (" WrongConstant ")
Public GpsLocationManager Context (Context) {
LocationManager=(locationManager) context. GetSystemService (context. LOCATION_SERVICE);
If (locationManager. IsProviderEnabled (locationManager. GPS_PROVIDER)) {
LocationManager. GetLastKnownLocation (locationManager. GPS_PROVIDER);
LocationManager. RequestLocationUpdates (locationManager. GPS_PROVIDER, 1000,
0, locationListener);
}
}

LocationListener LocationListener=new LocationListener () {

@ Override
Public void onStatusChanged (String provider, int status, Bundle extras) {

}

@ Override
Public void onProviderEnabled (String provider) {
The e (the TAG, the provider);
}

@ Override
Public void onProviderDisabled (String provider) {
The e (the TAG, the provider);
}

@ Override
Public void onLocationChanged Location (Location) {
If (the location!=null) {
The e (TAG, "the Location changed: Lat:" +
The location. GetLatitude () + "Lng:" + location. GetLongitude ());
//position change
Latitude=location. GetLatitude ();
Longitude=location. GetLongitude ();
}
}
};

}

CodePudding user response:

This is the log

  • Related