Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work in Headless JS #407

Open
valery-lavrik opened this issue Mar 20, 2023 · 2 comments
Open

Does not work in Headless JS #407

valery-lavrik opened this issue Mar 20, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@valery-lavrik
Copy link

Good afternoon! In the simple mode of the application, everything works well.
Permissions have already been requested and received.

Now I want the Headless (https://reactnative.dev/docs/headless-js-android) script to work with coordinates, but I always get null

Here are excerpts from the code:

index.js

...
import { BackgroundTask } from './src/utils/BackgroundHeadlessJSTask';

AppRegistry.registerHeadlessTask('Sync', () => BackgroundTask);
AppRegistry.registerComponent(appName, () => App);

BackgroundHeadlessJSTask.js

export const BackgroundTask = () => {
	Geolocation.getCurrentPosition(
		(position) => {
			console.log('position', position);
		},
		(error) => {
			// error.code: 3    
			// error.message:  Location request timed out.
			console.log(error);
		},
		{
			timeout: (1000 * timeout),
			maximumAge: (1000 * 60 * 2),
			enableHighAccuracy: true,
		}
	);
};


After analyzing the situation, I began to receive an error:
Location request timed out.

I do not know what to do...

@valery-lavrik valery-lavrik added the bug Something isn't working label Mar 20, 2023
@kv77724-dot
Copy link

Good afternoon! In the simple mode of the application, everything works well. Permissions have already been requested and received.

Now I want the Headless (https://reactnative.dev/docs/headless-js-android) script to work with coordinates, but I always get null

Here are excerpts from the code:

index.js

...
import { BackgroundTask } from './src/utils/BackgroundHeadlessJSTask';

AppRegistry.registerHeadlessTask('Sync', () => BackgroundTask);
AppRegistry.registerComponent(appName, () => App);

BackgroundHeadlessJSTask.js

export const BackgroundTask = () => {
	Geolocation.getCurrentPosition(
		(position) => {
			console.log('position', position);
		},
		(error) => {
			// error.code: 3    
			// error.message:  Location request timed out.
			console.log(error);
		},
		{
			timeout: (1000 * timeout),
			maximumAge: (1000 * 60 * 2),
			enableHighAccuracy: true,
		}
	);
};

After analyzing the situation, I began to receive an error: Location request timed out.

I do not know what to do...

any solution?

@valery-lavrik
Copy link
Author

valery-lavrik commented Aug 27, 2023

I fixed the problem in the fork of this library. You can use it.
https://github.com/valery-lavrik/react-native-geolocation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants