react-native-geolocation-service: TypeError: Cannot read property 'getCurrentPosition' of undefined

After all setup I have this issue::

> TypeError: Cannot read property 'getCurrentPosition' of undefined
>     at Object.getCurrentPosition$ (blob:http://localhost:8081/0786bd13-e17c-404e-8e19-b46bdfbaf7f3:162211:33)
>     at tryCatch (blob:http://localhost:8081/0786bd13-e17c-404e-8e19-b46bdfbaf7f3:21370:19)
>     at Generator.invoke [as _invoke] (blob:http://localhost:8081/0786bd13-e17c-404e-8e19-b46bdfbaf7f3:21543:24)
>     at Generator.prototype.(anonymous function) [as next] (blob:http://localhost:8081/0786bd13-e17c-404e-8e19-b46bdfbaf7f3:21413:23)
>     at tryCatch (blob:http://localhost:8081/0786bd13-e17c-404e-8e19-b46bdfbaf7f3:21370:19)
>     at invoke (blob:http://localhost:8081/0786bd13-e17c-404e-8e19-b46bdfbaf7f3:21446:22)
>     at blob:http://localhost:8081/0786bd13-e17c-404e-8e19-b46bdfbaf7f3:21474:13
>     at tryCallTwo (blob:http://localhost:8081/0786bd13-e17c-404e-8e19-b46bdfbaf7f3:20708:7)
>     at doResolve (blob:http://localhost:8081/0786bd13-e17c-404e-8e19-b46bdfbaf7f3:20872:15)
>     at new Promise (blob:http://localhost:8081/0786bd13-e17c-404e-8e19-b46bdfbaf7f3:20731:5)

Steps I have followed::

After these I have installed “react-native-geolocation-service” package Link this package I have followed all the Android settings. Import in file like this:: import Geolocation from “react-native-geolocation-service”; Function where I used it::

getLocation() {
		Geolocation.getCurrentPosition(response => {
			console.log("geo response = ", response);
			if (response && response.coords) {
				console.log("geo res true");
				this.saveLocationLogs(response.coords);
			}
		},
			(error) => {
				console.log("Error geolocation");
				this.onGeolocationErrorOccurCallback(error);
			},
			GeolocationOptions
		).catch((error) => {
			console.log(error);
		});
	}

There is a TypeError: cannot read property getCurrentPosition of undefined. still I am not able to get my current location?? Why this is happening? Please suggest me a solution.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (5 by maintainers)

Most upvoted comments

fuck u github…u dont have solutions for our questions

Check These lines added in your MainApplication.java

import com.agontuk.RNFusedLocation.RNFusedLocationPackage;

new RNFusedLocationPackage() in protected List<ReactPackage> getPackages() method

It fixes my issue

react-native: 0.61.4 react-native-geolocation-service: 3.1.0

react-native link @react-native-community/react-native-geolocation-service resolved this issue for me.

Indeed follow the steps for 0.59 and lower if this error occurs. ‘No additional setup is required for 0.60 or above’ sounds tempting.