getCurrentPosition returns immediately with undefined instead of result from onSuccess argument
See original GitHub issueEnvironment
System:
OS: macOS 12.0.1
CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
Memory: 24.38 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.17.4 - /usr/local/bin/node
Yarn: Not Found
npm: 8.5.3 - /usr/local/bin/npm
Watchman: 2021.08.30.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.11.3 - /Users/rafael/.rbenv/shims/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 15.4, macOS 12.3, tvOS 15.4, watchOS 8.5
Android SDK:
API Levels: 28, 29, 30, 31
Build Tools: 28.0.3, 29.0.2, 30.0.2, 31.0.0
System Images: android-29 | Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: 2020.3 AI-203.7717.56.2031.7583922
Xcode: 13.3/13E113 - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_292 - /usr/bin/javac
Python: 3.9.6 - /Users/rafael/.pyenv/shims/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.13.1 => 16.13.1
react-native: 0.63.4 => 0.63.4
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
Platforms
Is this issue related to Android, iOS, or both ? Both
Versions
- Android: 11
- iOS: 15.4
- react-native-geolocation-service: ^2.0.2
- react-native: 0.63.4
- react: 16.13.1
Description
Instead of returning result from onSuccess
param, getCurrentPosition
returns immediately with undefined
, and callback is called afterwards.
Reproducible Demo
const test = async () => {
console.log("Starting test");
const result = await getCurrentPosition(
(position) => {
console.log("Got position");
return true;
},
);
console.log("Finishing test, result:", result);
);
Expected Results
Expected logs:
Starting test
Got position
Finishing test, result: true
Actual logs:
Starting test
Finishing test, result: undefined
Got position
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
navigator.geolocation.getCurrentPosition sometimes works ...
It does not time the user to allow or deny the geolocation request, but how long the network is allowed to take to...
Read more >Geolocation.getCurrentPosition() - Web APIs | MDN
A positive long value indicating the maximum age in milliseconds of a possible cached position that is acceptable to return.
Read more >MediaPlayer - Android Developers
Although the asynchronuous seekTo(long, int) call returns right away, the actual seek operation may take a while to finish, especially for audio/video being ......
Read more >cordova-plugin-geolocation
navigator.geolocation.getCurrentPosition. Returns the device's current position to the geolocationSuccess callback with a Position object as the parameter.
Read more >Why does the geolocation API return undefined? - Reddit
The below code returns undefined. Why is that? In my mind the logic would be that the getLocation(), upon a successful retrieval of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Closing this as latest version contains the proper typings.
Actually,
getCurrentPosition
is async (returns aPromise
) in the version I have (2.0.2
). At least that’s whatindex.d.ts
is describes it as. Lines 61-65: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: