Maidenhead grid locator and WGS84 coordinate calculation and transformation
npm i @hamset/maidenhead-locator
import {
validateGridLocator,
WGS84ToMaidenhead,
maidenheadToWGS84,
maidenheadToBoundingBox,
GridLocator,
WGS84,
LatLng
} from '@hamset/maidenhead-locator';
// convert maidenhead grid locator to WGS84 coordinate
const grid_locator = 'DM06gs'
const coordinate: WGS84 = maidenheadToWGS84(grid_locator);
// output: { lat: 36.75, lng: -119.5 }
// convert WGS84 coordinate to maidenhead grid locator
const coordinate: LatLng = { lat: 36.75, lng: -119.5 }
const grid_locator: GridLocator = WGS84ToMaidenhead(coordinate);
// output: 'DM06gs'
// get bounding box coordinates from maidenhead grid locator
const grid_locator = 'DM06gs'
const bounds: [LatLng, LatLng] = maidenheadToBoundingBox(grid_locator);
// output: [ [ 36.75, -119.5 ], [ 36.791666666666664, -119.41666666666667 ] ]
import { CoordinateLike, GridLocator, WGS84 } from "./types";
/**
* Validate grid locator
* @param gridLocator grid locator
* @returns true if the grid locator is valid
*/
declare const validateGridLocator: (gridLocator: GridLocator) => boolean;
/**
* Convert WGS84 to Maidenhead
* @param coord coordinate
* @returns grid locator
*/
declare const WGS84ToMaidenhead: (coord: CoordinateLike) => GridLocator;
/**
* Convert Maidenhead to WGS84
* @param gridLocator grid locator
* @returns coordinate
*/
declare const maidenheadToWGS84: (gridLocator: GridLocator) => WGS84;
/**
* Convert Maidenhead to bounding box coordinates
* @param gridLocator grid locator
* @returns A two-dimensional array containing two diagonal coordinates of bounds
*/
declare const maidenheadToBoundingBox: (gridLocator: GridLocator) => [LatLng, LatLng];
//
// types
//
export type LatLng = [number, number];
export interface WGS84 {
lat: number;
lng: number;
}
export type CoordinateLike = LatLng | WGS84;
export type LatLngBounds = [LatLng, LatLng];
export type GridLocator = string;