react-native-community-geolocation

Module Gelocation for react-native

Usage no npm install needed!

<script type="module">
  import reactNativeCommunityGeolocation from 'https://cdn.skypack.dev/react-native-community-geolocation';
</script>

README

react-native-community-geolocation

npm Supports Android MIT License

npm total downloads npm monthly downloads npm weekly downloads

Device Information for React Native.
Here's an image the example:

Move along.

Getting started

Until now only Android

using yarn

$ yarn add react-native-community-geolocation --save

using npm

$ npm install react-native-community-geolocation --save

Mostly automatic installation react version < 0.6

$ react-native link react-native-community-geolocation

Usage

import React, { useState, useEffect } from "react";
import { StyleSheet, Text, View, Button } from "react-native";
import Geolocation from "react-native-community-geolocation";

export default function App() {
  const [status, setStatus] = useState("starting");
  const [message, setMessage] = useState("message");

  async function getGeolocation() {
    /*
     *until now options
     *provider disponibles:
     *gps (accuracy: ~= 3.41 (m))
     *network (accuracy:~= 14.44(m))
     */
    const options = { provider: "gps" || "network" };
    const position = await Geolocation.getCurrentPosition({ provider: "gps" });
    setMessage(position);
  }
  return (
    <View style={styles.container}>
      <Text style={styles.welcome}>☆Geolocation example☆</Text>
      <Text style={styles.instructions}>STATUS: {status}</Text>
      <Text style={styles.welcome}>☆NATIVE CALLBACK MESSAGE☆</Text>
      <Text style={styles.instructions}>{message}</Text>
      <Button title="Press" onPress={() => getGeolocation()} />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
    backgroundColor: "#F5FCFF"
  },
  welcome: {
    fontSize: 20,
    textAlign: "center",
    margin: 10
  },
  instructions: {
    textAlign: "center",
    color: "#333333",
    marginBottom: 5
  }
});

Method

Name Param Type values
getCurrentPosition option object provider

Params

Name Key Values
options provider network or gps

as soon as possible I will study objective c for implementation thanks to everyone who uses ^^.