Created
April 23, 2015 17:57
-
-
Save mohamedmansour/6c8d4e342f9c791d8d55 to your computer and use it in GitHub Desktop.
C++/CX Geolocation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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