GetGeopositionAsync does not return

后端 未结 10 687
北恋
北恋 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:40

    This weird behaviour happens when the status of geolocator is in NotInitialized state while calling the GetGeopositionAsync().

    The geolocator is only Ready in two cases. One, when it is subscribed to a PositionChanged event. Two, when a GetGeopositionAsync() is called already.

    So, you just have to subscribe the geolocator to a positionChanged event before calling the GetGeopositionAsync().

    Hope this helps.

    0 讨论(0)
  • 2021-01-08 00:42

    I had this issue when testing on a Device. I had to disable the WiFi on the device in order to get it to work. I know that some people have had the opposite problem working on the emulator. I did not have to do any wrapping. Hope it Helps

    0 讨论(0)
  • 2021-01-08 00:42

    I had some of the same issues above. When I hooked up to the geolocator.StatusChanged event, I noticed that sequence of events was:

    1. StatusChanged -> Initializing
    2. My await call
    3. StatusChanged -> Ready

    So I added a loop before my await call:

      while (geolocator.LocationStatus == PositionStatus.Initializing)
      {
          System.Threading.Thread.Sleep(100);
      }
    

    This is inelegant, but did work.

    0 讨论(0)
  • 2021-01-08 00:44

    When are you calling the method to request the geoposition? I found I encountered the same issue when I made the call part of the constructor in my ViewModel.

    I was able to fix the problem in my code by adding an OnLoadedCommand and calling the method from there. I've had no further issues since.

    0 讨论(0)
提交回复
热议问题