React native, geo-location libraries not providing precise coordinates sometimes

Viewed 5

Please Help!

I'm tried using react-native's two different libraries for getting user's longitude and latitude. It provides the coordinates but not correct all the times, 80% of attempts to get coordinates are correct but rest of the 20% are incorrect and that is a problem.

Two different smart phones at same location provides different coordinates. I have to compare the location of user with location of other.

I tried exploring internet for the solution but unable to solve the problem. Below is my code for both of the libraries.

import GetLocation from 'react-native-get-location';


 const location = await GetLocation.getCurrentPosition({
            enableHighAccuracy: true,
            timeout: 30000,
            maximumAge: 0,
        });
 if (location) console.log(location);

//Second one

import Geolocation from 'react-native-geolocation-service';

Geolocation.getCurrentPosition(
                (location) => {
                    console.log(location); 
                        },
                (error) => {
                    console.log(error.code, error.message);                   
                },
                {
                    enableHighAccuracy: true,
                    timeout: 30000,
                    maximumAge: 0,
                    forceLocationManager: true,
                    forceRequestLocation: true
                }
 );

"react": "16.13.1",

"react-native-geolocation-service": "^5.2.0",

"react-native-get-location": "^2.0.0",

build.gradle file

ext {
        buildToolsVersion = "29.0.2"
        minSdkVersion = 21
        compileSdkVersion = 29
        targetSdkVersion = 29
        androidXCore = "1.0.2"
        googlePlayServicesVersion = "17.1.0"
}
0 Answers
Related