Skip to main content


Utilities to work with geolocation links and coordinates. Available since version 1.9.2.

Get current position

This is a wrapper around navigator.getCurrentPosition() with some modern adaptations.

The request is promisified and the Error is completed with the name parameter.

import { Geolocation } from 'eyeson';

try {
const { latitude, longitude } = await Geolocation.getCurrentPosition();
} catch (error) {
if ( === 'NotAllowedError') {
console.log('The page didn\'t have the necessary permissions, for example because it is blocked.');
else if ( === 'PositionUnavailableError') {
console.log('Geolocation failed because at least one internal source of position returned an internal error.');
else if ( === 'TimeoutError') {
console.log('The time allowed to acquire the geolocation was reached.');

The result also contains accuracy, altitude, heading, and speed. See:

Good to know: The Error is still a GeolocationPositionError, so you can also match the code parameter.

if (error instanceof GeolocationPositionError) {
switch (error.code) {
case GeolocationPositionError.PERMISSION_DENIED:
case GeolocationPositionError.POSITION_UNAVAILABLE:
case GeolocationPositionError.TIMEOUT:

Check support

The geolocation support check can be found in FeatureDetector. It can be used together with Geolocation.getCurrentPosition().

import { FeatureDetector } from 'eyeson';

const isSupported = FeatureDetector.canGeolocation();

Permission check

This can be called any time before Geolocation.getCurrentPosition(). Show a hint to the user if permission is denied. No try-catch needed, in case of an error "prompt" is returned.

import { Geolocation } from 'eyeson';

const state = await Geolocation.getPermissionStatus();
switch (state) {
case 'prompt':
case 'granted':
case 'denied':

Helper functions to generate or parse links with location information with common online maps services.

Given latitude and longitude values, you can generate links to a number of common online maps services like Google Maps, etc.

import { Geolocation } from 'eyeson';

const latitude = 48.2154648; // double or string
const longitude = 16.397599; // double or string
const {
} = Geolocation.generateLinkFromCoordinates(latitude, longitude);

console.log(googleMaps); //,16.397599

Extract latitude and longitude values from links of common online maps services.

Currently supported:

  • Google Maps
  • OpenStreetMap
  • Bing Maps
  • HERE WeGo
import { Geolocation } from 'eyeson';

if (Geolocation.linkContainsCoordinates(link)) {
const { latitude, longitude } = Geolocation.parseCoordinatesFromLink(link);

// OR

const parsed = Geolocation.parseCoordinatesFromLink(link);
if (parsed !== null) {
const { latitude, longitude } = parsed;