browser-location

Geolocation for the browser with a Node-friendly API

Usage no npm install needed!

<script type="module">
  import browserLocation from 'https://cdn.skypack.dev/browser-location';
</script>

README

browser-location Build Status

Geolocation for the browser with a Node-friendly API

Install

$ npm install --save browser-location

Usage

var location = require('browser-location')

location.get(function (err, position) {
  //=> null, {coords: {...}, timestamp: ...}  
})

API

location.get([options], callback) -> undefined

options

Type: object
Default: {}

A PositionsOptions object that will be passed to the geolocation API.

callback

Required
Type: function Arguments: err, position

A callback that will be called with an error or a Position object. The error will be a GeolocationNotSupported error if geolocation is not supported. Otherwise it will be a PositionError.

location.GeolocationNotSupportedError(message) -> error

The constructor for the error that is returned in browsers that do not support geolocation. Exposed as a convenience so your code can distinguish between error states.

message

Type: string
Default: 'Geolocation is not supported'

License

MIT © Ben Drucker