Last active
September 24, 2023 15:28
-
-
Save OkancanCosar/90c57205770f50ee489a055cbe0d3bdf to your computer and use it in GitHub Desktop.
RN Geolocation convert promise to async/await
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Geolocation from "react-native-geolocation-service"; | |
const getCurrentLatLong = async () => { | |
const opt = { | |
// timeout:INFINITY, | |
// maximumAge:INFINITY, | |
// accuracy: { ios: "hundredMeters", android: "balanced" }, | |
// enableHighAccuracy: false, | |
// distanceFilter:0, | |
showLocationDialog: true, | |
forceRequestLocation: true, | |
}; | |
const getCurrentPosition = () => new Promise((resolve, error) => Geolocation.getCurrentPosition(resolve, error, opt)); | |
try { | |
const Data = await getCurrentPosition(); | |
const Latlong = `${Data?.coords?.latitude}, ${Data?.coords?.longitude}`; | |
return { Status: true, Data, Latlong }; | |
} catch (error) { | |
console.log("getCurrentLatLong::catcherror =>", error); | |
return { Status: false, Message: Strings.Geolocation.Error(error.code) }; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment