use-geolocation3
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

use-geolocation3

Access and monitor a user's geolocation (after they give permission) with useGeolocation.

Installation

To install the package, use npm:

pnpm add use-geolocation3

yarn install use-geolocation3

npm install use-geolocation3

Usage

import React from "react";
import { useGeolocation } from "use-geolocation3";

const GeolocationComponent: React.FC = () => {
  const {
    loading,
    latitude,
    longitude,
    accuracy,
    altitude,
    altitudeAccuracy,
    heading,
    speed,
    error,
    timestamp,
  } = useGeolocation();

  return (
    <div>
      <h2>Geolocation Information</h2>
      {loading && <p>Loading...</p>}
      {error && <p>Error: {error.message}</p>}

      {!loading && !error && (
        <div>
          <p>Latitude: {latitude}</p>
          <p>Longitude: {longitude}</p>
          <p>Accuracy: {accuracy} meters</p>
          {altitude !== null && <p>Altitude: {altitude} meters</p>}
          {altitudeAccuracy !== null && (
            <p>Altitude Accuracy: {altitudeAccuracy} meters</p>
          )}
          {heading !== null && <p>Heading: {heading} degrees</p>}
          {speed !== null && <p>Speed: {speed} m/s</p>}
          <p>Timestamp: {new Date(timestamp!).toLocaleTimeString()}</p>
        </div>
      )}
    </div>
  );
};

export default GeolocationComponent;

tsup

Bundle your TypeScript library with no config, powered by esbuild.

https://tsup.egoist.dev/

How to use this

  1. install dependencies
# pnpm
$ pnpm install

# yarn
$ yarn install

# npm
$ npm install
  1. Add your code to src
  2. Add export statement to src/index.ts
  3. Test build command to build src. Once the command works properly, you will see dist folder.
# pnpm
$ pnpm run build

# yarn
$ yarn run build

# npm
$ npm run build
  1. Publish your package
$ npm publish

test package

https://www.npmjs.com/package/use-geolocation3

Readme

Keywords

none

Package Sidebar

Install

npm i use-geolocation3

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

258 kB

Total Files

19

Last publish

Collaborators

  • dimetrix