Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including geokit with all npm packages installed. Try it out:

var geokit = require("geokit")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

geokit v0.1.3

An assortment of geolocation related tools, all packaged in one easy to use kit.

geokit

Build Status npm version Coverage Status

An assortment of geolocation related tools, all packaged in one easy to use kit.

Methods

Geokit.distance(start: LatLngLiteral, end: LatLngLiteral, unit?: string): number

Static method which returns the distance, in kilometers, between start and end.

start and end must be LatLngLiterals { lat: 0, lng: 0 }.

There exists an optional third argument, where if the string 'miles' is inputted, the result returned will be in miles rather than kilometers.

import { Geokit, LatLngLiteral } from 'geokit';

const start: LatLngLiteral = { lat: 40.7128,  lng: -74.0060 };
const end: LatLngLiteral = { lat: 37.7749,  lng: -122.4194 };

const distance: number = Geokit.distance(location1, location2, 'miles');  // distance === 2568.4458439997047

Geokit.hash(coordinates: LatLngLiteral, precision?: number): string

Static method which generates the geohash of a point.

coordinates must be LatLngLiterals { lat: 0, lng: 0 }.

There exists an optional second argument of precision, where the hash produced will be as many characters as the number inputted. It defaults to 10.

import { Geokit, LatLngLiteral } from 'geokit';

const coordinates: LatLngLiteral = { lat: 41.3083,  lng: -72.9279 };

const hash: string = Geokit.hash(coordinates);  // hash === 'drk4urzw2c'

Geokit.decodeHash(hash: string): LatLngLiteral

Static method which decodes geohash into its Latitude and Longitude as a LatLngLiteral.

import { Geokit, LatLngLiteral } from 'geokit';

const hash: string = 'r3gx2f77b';

const coordinates: LatLngLiteral = Geokit.decodeHash(hash);  // coordinates === { lat: -33.86881113052368,  lng: 151.2093186378479 }
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free