geo-uri
v0.0.0
Published
A TypeScript implementation of the [Geo URI Specification (RFC 5870)](https://datatracker.ietf.org/doc/html/rfc5870) that provides encoding and decoding of geographic coordinates.
Downloads
164
Readme
Geo URI
A TypeScript implementation of the Geo URI Specification (RFC 5870) that provides encoding and decoding of geographic coordinates.
Installation
npm install geo-uriyarn add geo-uriUsage
import { decodeGeoUri, encodeGeoUri, Wgs84GeoUri } from 'geo-uri';
// Decode a Geo URI string
const location = decodeGeoUri('geo:40.714623,-74.006605');
// {
// scheme: 'wgs84',
// latitude: 40.714623,
// longitude: -74.006605,
// altitude: undefined,
// uncertainty: undefined
// }
// Encode a Geo URI object to a string
const geoObject: Wgs84GeoUri = {
type: "supported",
scheme: 'wgs84',
latitude: 40.714623,
longitude: -74.006605,
altitude: 100.5,
uncertainty: 10
};
const encoded = encodeGeoUri(geoObject);
// geo:40.714623,-74.006605,100.5;crs=wgs84;u=10Error Handling
The decodeGeoUri function returns an InvalidGeoUri object if the input string is not a valid Geo URI:
const result = decodeGeoUri('invalid:40.714623,-74.006605');
if (result.type === 'invalid') {
console.error(result.message); // "Invalid Geo URI"
}API Reference
Functions
decodeGeoUri(geoUri: string): GeoUri | InvalidGeoUri
Decodes a Geo URI string into a structured object.
encodeGeoUri(data: GeoUri): string
Encodes a GeoUri object into a valid Geo URI string.
Types
GeoUri
Union type of supported and unsupported Geo URIs.
SupportedGeoUri
Represents coordinate systems supported by the RFC specifications.
Wgs84GeoUri
Represents WGS84 coordinates with latitude, longitude, optional altitude.
UnsupportedGeoUri
Represents coordinates in an unsupported coordinate reference system.
InvalidGeoUri
Represents an invalid Geo URI with an error message.
License
MIT
