Skip to content

Instantly share code, notes, and snippets.

@mohamedmansour
Created April 23, 2015 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohamedmansour/6c8d4e342f9c791d8d55 to your computer and use it in GitHub Desktop.
Save mohamedmansour/6c8d4e342f9c791d8d55 to your computer and use it in GitHub Desktop.
C++/CX Geolocation
task<GeolocationAccessStatus> geolocationAccessRequestTask(Windows::Devices::Geolocation::Geolocator::RequestAccessAsync());
geolocationAccessRequestTask.then([this](task<GeolocationAccessStatus> accessStatusTask)
{
// Get will throw an exception if the task was canceled or failed with an error
auto accessStatus = accessStatusTask.get();
if (accessStatus == GeolocationAccessStatus::Allowed)
{
// LOG: Waiting for update...
auto geolocator = ref new Windows::Devices::Geolocation::Geolocator();
geolocator->DesiredAccuracyInMeters = desiredAccuracyInMetersValue;
task<Geoposition^> geopositionTask(geolocator->GetGeopositionAsync(), geopositionTaskTokenSource.get_token());
geopositionTask.then([this](task<Geoposition^> getPosTask)
{
// LOG: Location updated.
// Get will throw an exception if the task was canceled or failed with an error
return LocationResult::CreateSuccessResult(getPosTask.get());
});
}
else if (accessStatus == GeolocationAccessStatus::Denied)
{
// LOG: Access to location is denied.
return LocationResult::CreateFailureResult(LocationStatus::Denied);
}
else //GeolocationAccessStatus::Unspecified:
{
// LOG: Unspecified error!
return LocationResult::CreateFailureResult(LocationStatus::Unspecified);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment