react-geolocation

?? Declarative geolocation for React

Github stars Tracking Chart

react-geolocation

?? Declarative geolocation in React

npm version
Build Status
codecov

Install

npm install -S react-geolocation

Basic Usage

<Geolocation
  render={({
    fetchingPosition,
    position: { coords: { latitude, longitude } = {} } = {},
    error,
    getCurrentPosition
  }) =>
    <div>
      <button onClick={getCurrentPosition}>Get Position</button>
      {error &&
        <div>
          {error.message}
        </div>}
      <pre>
        latitude: {latitude}
        longitude: {longitude}
      </pre>
    </div>}
/>

Props

enableHighAccuracy boolean

timeout number

maximumAge number

render function

render is a function that receives an object as its only argument.

The object contains the following keys:

  • fetchingPosition: bool
  • position: object
  • error: object
  • getCurrentPosition: function

lazy boolean

If true then the component will not perform the fetch on mount.
You must use the getCurrentPosition named argument in order to initiate the request.

<Geolocation 
  lazy 
  render={({getCurrentPosition, fetchingPosition}) => (
    <div>
      <button onClick={getCurrentPosition}>Get Current Position</button>
      <div>Fetching Position: {fetchingPosition}</div>
    </div>
  )}
/> 
// renders "Fetching Position: false" until the button is clicked

onSuccess function

callback called on success. Its only argument is position

onError function

callback called on error. Its only argument is error

Main metrics

Overview
Name With Ownertkh44/react-geolocation
Primary LanguageJavaScript
Program languageJavaScript (Language Count: 1)
Platform
License:MIT License
所有者活动
Created At2017-08-13 06:22:14
Pushed At2018-12-17 22:50:38
Last Commit At2018-12-17 14:50:37
Release Count3
Last Release Namev1.0.3 (Posted on 2017-08-15 16:28:30)
First Release Namev1.0.1 (Posted on 2017-08-13 00:44:38)
用户参与
Stargazers Count242
Watchers Count5
Fork Count25
Commits Count25
Has Issues Enabled
Issues Count8
Issue Open Count2
Pull Requests Count4
Pull Requests Open Count0
Pull Requests Close Count0
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private