1.0.0 • Published 4 years ago

@22hbg/rn-geolocalization-module v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Geolocalization module

React Native module with geolocalization

Dependecy used: React Native Geolocalization Service

Installation

yarn add @22hbg/rn-geolocalization-module react-native-geolocation-service

cd ios/ && pod install

Additional steps:

Android setup\ iOS setup

Usage

Get current position

import React, { useEffect } from 'react'
import { Text } from 'react-native'
import { getPosition } from '@22hbg/rn-geolocalization-module'
import { GeoCoordinates } from 'react-native-geolocation-service'

export default App = () => {
    const [position, setPosition] = useState<GeoCoordinates>(null)

    useEffect(() => {
        getInitialPosition()
    })

    const getInitialPosition = async () => {
        try {
            const coords = await getPosition(
                {
                    enableHighAccuracy: false
                },
                'whenInUse'
            )

            setPosition(coords)
        } catch (e) {
            console.log('error')
        }
    }

    if (!position) {
        return null
    }

    return <Text>{`Lat. ${coords.latitude} Lng. ${coords.longitude}`}</Text>
}

export default App