From ee08eea49cb997223eda23c7dc58fcf8194227ae Mon Sep 17 00:00:00 2001 From: Jai Dhyani Date: Thu, 14 Apr 2022 17:27:43 -0700 Subject: [PATCH] Use UniAndroid to check permission status In the existing implementation, `_gotPermissionRequestResponse` is not reliably set when the user sets permission, which can leave the application in a broken state that can only be resolved by force-quitting and restarting. Using UniAndroid instead seems to fix the issue and results in the application being in a working state after the user accepts the permission request. --- .../Mapbox/Unity/Location/DeviceLocationProvider.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sdkproject/Assets/Mapbox/Unity/Location/DeviceLocationProvider.cs b/sdkproject/Assets/Mapbox/Unity/Location/DeviceLocationProvider.cs index ae5142631..bcf37b2db 100644 --- a/sdkproject/Assets/Mapbox/Unity/Location/DeviceLocationProvider.cs +++ b/sdkproject/Assets/Mapbox/Unity/Location/DeviceLocationProvider.cs @@ -164,7 +164,7 @@ IEnumerator PollLocationRoutine() { UniAndroidPermission.RequestPermission(AndroidPermission.ACCESS_FINE_LOCATION); //wait for user to allow or deny - while (!_gotPermissionRequestResponse) { yield return _wait1sec; } + while (!UniAndroidPermission.IsPermitted(AndroidPermission.ACCESS_FINE_LOCATION)) { yield return _wait1sec; } } #endif @@ -316,9 +316,9 @@ IEnumerator PollLocationRoutine() // atan2 increases angle CCW, flip sign of latDiff to get CW double latDiff = -(_lastPositions[i].x - _lastPositions[i - 1].x); double lngDiff = _lastPositions[i].y - _lastPositions[i - 1].y; - // +90.0 to make top (north) 0° + // +90.0 to make top (north) 0° double heading = (Math.Atan2(latDiff, lngDiff) * 180.0 / Math.PI) + 90.0f; - // stay within [0..360]° range + // stay within [0..360]° range if (heading < 0) { heading += 360; } if (heading >= 360) { heading -= 360; } lastHeadings[i - 1] = (float)heading; @@ -327,7 +327,7 @@ IEnumerator PollLocationRoutine() _userHeadingSmoothing.Add(lastHeadings[0]); float finalHeading = (float)_userHeadingSmoothing.Calculate(); - //fix heading to have 0° for north, 90° for east, 180° for south and 270° for west + //fix heading to have 0° for north, 90° for east, 180° for south and 270° for west finalHeading = finalHeading >= 180.0f ? finalHeading - 180.0f : finalHeading + 180.0f;