1.0.14 • Published 12 months ago

gekko-geolocation v1.0.14

Weekly downloads
-
License
ISC
Repository
-
Last release
12 months ago

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: 1. Init gekko-geolocation service in App.js file 2. Set users phone number in auth flow of the app 3. 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)
1.0.14

12 months ago

1.0.12

12 months ago

1.0.11

12 months ago

1.0.10

12 months ago

1.0.9

12 months ago

1.0.8

12 months ago

1.0.7

12 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago