CrossGeolocator.Current.GetPositionAsync提供null Exception Xamarin.Forms

时间:2016-06-06 11:22:45

标签: xamarin xamarin.ios xamarin.android xamarin.forms

我想在Map上显示当前位置。为此我使用了Geolocator插件。我有代码获取设备的当前位置。

[async void Maplaunch()
        {
            try
            {
                var locator = CrossGeolocator.Current;
                locator.DesiredAccuracy = 50;
                var pos = await locator.GetPositionAsync(10000);
                var approximateLocations = await geoCoder.GetPositionsForAddressAsync(TxtSerch.Text);
                var position = new Position(approximateLocations.First().Latitude, approximateLocations.First().Longitude);
                var possibleAddresses = await geoCoder.GetAddressesForPositionAsync(position);
                var pin = new Pin
                {
                    Type = PinType.Place,
                    Position = new Position(approximateLocations.First().Latitude, approximateLocations.First().Longitude),
                    Label = possibleAddresses.First().ToString(),
                    Address = possibleAddresses.First().ToString()
                };
                HomeMap.Pins.Add(pin);
                HomeMap.MoveToRegion(MapSpan.FromCenterAndRadius(position, Distance.FromMiles(1.0)));
            }
            catch (Exception ex)
            {

            }
        }]

但是当我调试CrossGeolocator.Current.GetPositionAsync(10000)时,我得到了异常。请帮助我。 Thanx提前。 Check Image of Issue

0 个答案:

没有答案