小编Gan*_*ikh的帖子

如何在Xamarin.forms中立即获得GPS位置?

Listview_ItemTapped通过使用Geolocator插件在xamarin.forms中获取GPS位置来捕获纬度和经度.但平均需要超过15秒来捕获位置.有没有办法立即获得位置.

if (CrossGeolocator.Current.IsGeolocationEnabled == false)
 {
    await DisplayAlert("Notification", "Geolocation is Unavailable ", "Ok");
 }
 else
 {
    Application.Current.Properties["LATITUDE"] = null;
     Application.Current.Properties["LONGITUDE"] = null;

    var locator = CrossGeolocator.Current;
    //locator.DesiredAccuracy = 50;               
    var position = await locator.GetPositionAsync(timeoutMilliseconds: 50000);

    Application.Current.Properties["LATITUDE"] = position.Latitude;
    Application.Current.Properties["LONGITUDE"] = position.Longitude;

    await Navigation.PushAsync(new RetailerDetailsPage(), false);
 }
Run Code Online (Sandbox Code Playgroud)

我尝试删除,locator.DesiredAccuracy = 50;但有时它会立即工作,有时它不会.

navigation gps location xamarin xamarin.forms

4
推荐指数
1
解决办法
5524
查看次数

标签 统计

gps ×1

location ×1

navigation ×1

xamarin ×1

xamarin.forms ×1