To get the current user position in Windows Phone 8 you can use the GeoLocator class that is very comfortable. You get a method containing two overloads.
- GetGeopositionAsync() – return the current postion (does not have a timeout)
- GetGeopositionAsync(maximumAge, timeout) – returns a cached position
Sometimes GetGeopositionAsync does not return. So you need to add a timeout procedure by your self. This way is works perfect.
Geolocator geolocator = new Geolocator(); // get the async task var asyncResult = geolocator.GetGeopositionAsync(); var task = asyncResult.AsTask(); // add a race condition - task vs timeout task var readyTask = await Task.WhenAny(task, Task.Delay(10000)); if (readyTask != task) // timeout wins throw new TimeoutException(); // position found within timeout var pos = await task; return pos;