My first application I developed for Windows Phone 8 relied heavily on the phone's current location, but I didn't need to track the location at all times. Naturally I tried to use the GeoLocator.GetGeopositionAsync() method found in all the documentation. However, I was finding that this method often ran indefinitely the first time trying to access the location.
After doing a lot of research and finding that many people were experiencing the same issues I decided to try a different approach. Ultimately I track the phone's location until I reached the desired accuracy, then stopping the tracking operation.
You can start tracking the user's location as follows:
Once we've started the tracking operation, the Position Changed event will fire every 30 milliseconds or once the distance changed reaches 100 meters. In my case, either is fine. The locator will update frequently as it finds more accurate position. Also, it's important to note that adding the
PositionChanged event handler implicitly starts the tracking operation.
If all you need is the one-time position of the phone, like you expected from
Geolocator.GetGeopositionAsync(), it's important to stop the tracking operation. This is important because tracking a phone's position drains the battery life drastically. Notice once I reach my desired accuracy of 500 meters I stop tracking by unsubscribing to the
Once I have a position at the desired accuracy, I save it to
IsolatedStorage that way I don't have to perform the costly operation again. I've left out implementation details specific to my application as to alleviate confusion. It's up to you how you want to notify your main thread that you have the phone's location.
Assuming Microsoft doesn't fix the problem, in the future I may create a cleaner way of doing this, for now this accomplishes what I need. Hope it helps!