Skip to content

Instantly share code, notes, and snippets.

@OkancanCosar
Last active September 24, 2023 15:28
Show Gist options
  • Save OkancanCosar/90c57205770f50ee489a055cbe0d3bdf to your computer and use it in GitHub Desktop.
Save OkancanCosar/90c57205770f50ee489a055cbe0d3bdf to your computer and use it in GitHub Desktop.
RN Geolocation convert promise to async/await
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