GetGeopositionAsync does not return

后端 未结 10 692
北恋
北恋 2021-01-08 00:13

In my Windows Phone 8 app, I am trying to use GetGeopositionAsync on the main page to display some items based on user location.

Calling GetGeopositionAsync does not

10条回答
  •  失恋的感觉
    2021-01-08 00:29

    This is strange but GetGeoPositionAsync only returns the current position when the Geolocator is initialized with either MovementThreshold and/or ReportInterval.

    Geolocator geolocator = new Geolocator();
    geolocator.DesiredAccuracyInMeters = 50;
    geolocator.MovementThreshold = 5;
    geolocator.ReportInterval = 500;
    
    Geoposition geoposition = null;
    try
    {
        geoposition = await geolocator.GetGeopositionAsync(
            maximumAge: TimeSpan.FromMinutes(5),
            timeout: TimeSpan.FromSeconds(10));
    }
    catch (UnauthorizedAccessException ex)
    {
        // location services disabled or other error
        // user should setup his location
    }
    

提交回复
热议问题