{"repo":"trekhleb/use-position","free":true,"listed":false,"github":"https://github.com/trekhleb/use-position","clone":"git clone https://github.com/trekhleb/use-position.git","description":"🌍 React hook usePosition() for fetching and following a browser geolocation","language":"JavaScript","stars":308,"topics":["react","hooks","location","position","browser","react-hook","react-hooks","geolocation"],"license":"MIT","category":"ui-components","readme_excerpt":"React hook for following a browser geolocation React hook usePosition() allows you to fetch a client's browser geolocation and/or subscribe to all further geolocation changes. ▶︎ Storybook demo of usePosition() hook. Installation Using yarn : Using npm : Usage Import the hook: Fetching client location Following client location In this case if browser detects geolocation change the latitude , longitude and timestamp values will be updated. Following client location with the highest accuracy The second parameter of usePosition() hook is position options. Full example Specification usePosition() input - watch: boolean - set it to true to follow the location. - settings: object - position options - settings.enableHighAccuracy - indicates the application would like to receive the most accurate results (default false ), - settings.timeout - maximum length of time (in milliseconds) the device is allowed to take in order to return a position (default Infinity ), - settings.maximumAge - the maximum age in milliseconds of a possible cached position that is acceptable to return (default 0 ). usePosition() output - latitude: number - latitude (i.e. 52.3172414 ), - longitude: number - longitude (i.e. 4.8717809 ), - speed: number null - velocity of the device in meters per second (i.e. 2.5 ), - timestamp: number - timestamp when location was detected (i.e. 1561815013194 ), - accuracy: number - location accuracy in meters (i.e. 24 ), - heading: number null - direction in which the device is","default_branch":null,"files":null,"tree":[],"storefront":"/r/trekhleb","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/trekhleb/use-position/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}