尝试在requestLocationUpdate中指定的时间内获取位置。但是OnLocationChanged事件在不同设备上的不同时间间隔上调用
INITIALIZE LOCATION MANAGER
private void InitializeLocationManager()
{
latlon.provider = new List<string>();
_locationManager = (LocationManager)GetSystemService(LocationService);
//Application criteria for selecting provider
Criteria criteriaForLocationService = new Criteria { Accuracy = Accuracy.NoRequirement };
IList<string> acceptableLocationProviders = _locationManager.GetProviders(criteriaForLocationService, true);
if (acceptableLocationProviders.Any())
{
_locationProvider = acceptableLocationProviders.First();
}
else
{
_locationProvider = String.Empty;
}
if (_locationProvider != null && _locationProvider != string.Empty)
{
//Request for gps in 10sec and 0 distance travelled
_locationManager.RequestLocationUpdates(_locationProvider, 10000, 0,
}
}
位置聆听界面
async public void OnLocationChanged(Location location)
{
try
{
_currentLocation = location;
if (_currentLocation == null)
{
}
else
{
Android.Util.Log.Info("GetLocation", "Latitude: " + _currentLocation.Latitude.ToString() + " Longitude: " + _currentLocation.Longitude.ToString());
}
}
catch (Exception ex)
{
Toast.MakeText(Application.Context, ex.Message, ToastLength.Long).Show();
}
}
public void OnProviderDisabled(string provider)
{
try
{
InitializeLocationManager();
}
catch (Exception ex)
{
Toast.MakeText(this, ex.Message, ToastLength.Long).Show();
}
}
public void OnProviderEnabled(string provider)
{
try
{
InitializeLocationManager();
}
catch (Exception ex)
{
Toast.MakeText(this, ex.Message, ToastLength.Long).Show();
}
}
public void OnStatusChanged(string provider, [GeneratedEnum] Availability status, Bundle extras)
{
Toast.MakeText(Application.Context, "status Changed", ToastLength.Long).Show();
}
在Xamarin.android中实现 Thanx提前
答案 0 :(得分:2)
它说
位置更新之间位置更新之间的最短时间间隔,以毫秒为单位
Minimum time
不是exact time
。所以不要依赖这个价值。