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
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.
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
I had some of the same issues above. When I hooked up to the geolocator.StatusChanged event, I noticed that sequence of events was:
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.
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.