【发布时间】:2018-02-10 20:16:22
【问题描述】:
我正在尝试从我的设备获取位置。这是代码:
public class Geolocation
{
private readonly LocationManager _locationManager;
public Geolocation()
{
_locationManager = Forms.Context.GetSystemService(Context.LocationService) as LocationManager;
}
public Task<double> GetLocation()
{
var provider = _locationManager.GetBestProvider(new Criteria() { Accuracy = Accuracy.Fine }, true);
var location = _locationManager.GetLastKnownLocation(provider);
if(location == null) return null;
var result = location.Latitude;
return result;
}
}
我从一本关于 xamarin 的书中得到了这段代码。我不明白,为什么大部分时间我都没有得到结果?几次都有效,但我不知道为什么。对于那些想知道为什么我不使用 James Montemagno 的 Geolocator 插件的人,因为我不能。它需要一些无法在我的 VS 中更新的内容。
【问题讨论】:
-
您能否详细说明为什么不能使用 GeoLocator 插件?哪些依赖项与哪些 NuGet 包冲突?
标签: c# xamarin.forms xamarin.android geolocation