gekko-geolocation
v1.0.14
Published
Gekko geolocation is service for background geolocation tracking based on react-native-background-geolocation and @react-native-firebase/database packages.
Downloads
20
Readme
gekko-geolocation
Background geolocation service for React Native Apps. Service tracks current location and saves it to Fire Base Realtime Database where key is encrypted users phone number and value is users current location. You can share your geolocation with other people by giving permission and also allow sharing for other persons phone number.
Instalation
npm
npm install gekko-geolocation
yarn
yarn add gekko-geolocation
Usage
First of all you have to configure react-native-background-geolocation and react-native-firebase/database packages. The Android module of react-native-background-geolocation requires purchasing a licence.
After configuring your app you have to do next steps:
- Init gekko-geolocation service in App.js file
- Set users phone number in auth flow of the app
- Set location listener and call
startListeningToLocationUpdates
function
Initialize gg service in App.js
import { FGLocationRetriever } from "gekko-geolocation";
const App = () => {
useEffect(() => {
FGLocationRetriever.getInstance().init();
}, []);
return <RootNavigator />;
};
export default App;
Set users phone number
FGLocationRetriever.getInstance().setUserPhone(phone: string);
Set location listener
const [users, setUsers] = useState([]);
const onUsersLocationUpdate = (locations) => {
const users = locations.map((location) => {
return {
phone: location.phone,
coordinates: [location.long, location.lat],
date: location.date,
key: location.key,
};
});
setUsers(users);
};
useFocusEffect(
React.useCallback(() => {
FGLocationRetriever.getInstance().setOnPhonesLocationsListener(
onUsersLocationUpdate
);
FGLocationRetriever.getInstance().startListeningToLocationUpdates();
// returned function will be called on component unmount
return () => {
FGLocationRetriever.getInstance().stopListeningToLocationUpdates();
};
}, [])
);
Control gg state
const [locationSharing, setLocationSharing] = useState(
FGLocationRetriever.getInstance().locationTrackingOn
);
useEffect(() => {
if (locationSharing) {
FGLocationRetriever.getInstance().startLocationTracking();
} else {
FGLocationRetriever.getInstance().stopLocationTracking();
}
}, [locationSharing]);
For sharing location with others
FGLocationRetriever.getInstance().addPhoneToTrack(phone: string)
FGLocationRetriever.getInstance().allowPhoneToTrackMe(phone: string)
Stop sharing location
FGLocationRetriever.getInstance().removePhoneToTrack(phone: string)
FGLocationRetriever.getInstance().disallowPhoneToTrackMe(phone: string)