gpt4 book ai didi

android - OnLocationChanged 在不同设备上以不同时间间隔触发

转载 作者:行者123 更新时间:2023-11-29 20:22:05 29 4
gpt4 key购买 nike

尝试在 requestLocationUpdate 指定的时间内获取位置。但是 OnLocationChanged 事件在不同的设备上以不同的时间间隔调用

初始化位置管理器

      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,
}
}

位置监听器接口(interface)

    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 中实现提前致谢

最佳答案

来自文档:http://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates(java.lang.String, long, float, android.location.LocationListener)

它说

minimum time interval between location updates, in milliseconds

最短时间 不是位置更新之间的确切时间。所以不要依赖这个值。

关于android - OnLocationChanged 在不同设备上以不同时间间隔触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33040713/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com