react-geolocation

?? Declarative geolocation for React

Github星跟踪图

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

主要指标

概览
名称与所有者tkh44/react-geolocation
主编程语言JavaScript
编程语言JavaScript (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2017-08-13 06:22:14
推送于2018-12-17 22:50:38
最后一次提交2018-12-17 14:50:37
发布数3
最新版本名称v1.0.3 (发布于 2017-08-15 16:28:30)
第一版名称v1.0.1 (发布于 2017-08-13 00:44:38)
用户参与
星数242
关注者数5
派生数25
提交数25
已启用问题?
问题数8
打开的问题数2
拉请求数4
打开的拉请求数0
关闭的拉请求数0
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?