GithubHelp home page GithubHelp logo

aijazargonteq / react-native-get-location Goto Github PK

View Code? Open in Web Editor NEW

This project forked from douglasjunior/react-native-get-location

0.0 0.0 0.0 464 KB

⚛ Simple to use React Native library to get native device location for Android and iOS.

Home Page: https://www.npmjs.com/package/react-native-get-location

License: MIT License

Java 45.55% JavaScript 16.37% Objective-C 35.84% Ruby 2.23%

react-native-get-location's Introduction

React-Native Get Location

Licence MIT npm version npm downloads

⚛ Simple to use React Native library to get native device location for Android and iOS.

Requirements

  • React Native >= 0.45.0
  • iOS >= 8.0

Install

Install dependency package

yarn add react-native-get-location

Or

npm i -S react-native-get-location

If you are using React Native 0.60.+ go to the folder your-project/ios and run pod install, and you're done.

If not, use one of the following method to link.

Link with react-native link

If you are using React Native <= 0.59.X, link the native project:

react-native link react-native-get-location

Android post install

For Android API < 23 you need to define the location permissions on AndroidManifest.xml.

<!-- Define ACCESS_FINE_LOCATION if you will use enableHighAccuracy=true  -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<!-- Define ACCESS_COARSE_LOCATION if you will use enableHighAccuracy=false  -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

iOS post install

You need to define the permission NSLocationWhenInUseUsageDescription on Info.plist.

<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs to get your location...</string>

Usage

There is only one function that you need to use to get the user's current location.

import GetLocation from 'react-native-get-location'

GetLocation.getCurrentPosition({
    enableHighAccuracy: true,
    timeout: 15000,
})
.then(location => {
    console.log(location);
})
.catch(error => {
    const { code, message } = error;
    console.warn(code, message);
})

For more details, see the Sample Project.

API

function GetLocation.getCurrentPosition(LocationConfig)

Parameters:

  • LocationConfig: Configuration object to determine how to get the user current location.

Return:

  • Promise<Location>: Promise thats resolve to a Location object.

Object LocationConfig

Properties:

  • enableHighAccuracy: Set true to use 'fine location' (GPS) our false to use 'course location' (Wifi, Bluetooth, 3G).
  • timeout: The max time (in milliseconds) that you want to wait to receive a location.

Object Location

Properties:

  • latitude: The latitude, in degrees.
  • longitude: The longitude, in degrees.
  • altitude: The altitude if available, in meters above the WGS 84 reference ellipsoid.
  • accuracy: The estimated horizontal accuracy of this location, radial, in meters.
  • speed: The speed if it is available, in meters/second over ground.
  • time: The UTC time of this fix, in milliseconds since January 1, 1970.
  • bearing: (Android only) The bearing, in degrees.
  • provider: (Android only) The name of the provider that generated this fix.
  • verticalAccuracy: (iOS only) The vertical accuracy of the location. Negative if the altitude is invalid.
  • course: (iOS only) The course of the location in degrees true North. Negative if course is invalid. (0.0 - 359.9 degrees, 0 being true North)

Error codes

Code Message
CANCELLED Location cancelled by user or by another request
UNAVAILABLE Location service is disabled or unavailable
TIMEOUT Location request timed out
UNAUTHORIZED Authorization denied

Contribute

New features, bug fixes and improvements are welcome! For questions and suggestions use the issues.

Become a Patron! Donate

Licence

The MIT License (MIT)

Copyright (c) 2019 Douglas Nassif Roma Junior

See the full licence file.

react-native-get-location's People

Contributors

douglasjunior avatar bradchristensen avatar mausic avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.