Closed rafabulsing closed 2 years ago
We have 2 problems:
getCurrentPosition
function is not asynchronous/promise.Actually, getCurrentPosition
is async (returns a Promise
) in the version I have (2.0.2
). At least that's what index.d.ts
is describes it as. Lines 61-65:
export function getCurrentPosition(
successCallback: SuccessCallback,
errorCallback?: ErrorCallback,
options?: GeoOptions
): Promise<GeoPosition>
In any case, I decided to do a workaround to get it to work as I need it to. Here it is, in case anyone is in the same situation:
const getLocation = (onSuccess, onError, options) => new Promise((resolve, reject) => {
Geolocation.getCurrentPosition(
(result) => resolve(onSuccess(result)),
(error) => reject(onError(error)),
options,
);
});
getCurrentPosition
is not an async function, it was a typo in the index.d.ts
. If possible, try to update to the latest version. You are using a pretty old version.
getCurrentPosition
is not an async function, it was a typo in theindex.d.ts
. If possible, try to update to the latest version. You are using a pretty old version.
You're right, in my case, at index.d.ts
the getCurrentPosition's return is actually typed as void, but I'm receiving this warning at my console:
Possible Unhandled Promise Rejection (id: 0): TypeError: Cannot read property 'getCurrentPosition' of null
Edit: I reinstalled the debug app and worked.
Closing this as latest version contains the proper typings.
Environment
Platforms
Is this issue related to Android, iOS, or both ? Both
Versions
Description
Instead of returning result from
onSuccess
param,getCurrentPosition
returns immediately withundefined
, and callback is called afterwards.Reproducible Demo
Expected Results
Expected logs:
Actual logs: