Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@conveyal/lonlat

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@conveyal/lonlat

Lon/lat normalization

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
301
increased by100.67%
Maintainers
1
Weekly downloads
 
Created
Source

lonlng

Lat/lon normalization cause...sigh.

No one has agreed on a standard way of representing lat/lon. This is a small normalization library. Use this to convert all outside input before processing internally and convert to an external format right when it's being output.

Just use the {lon: ${longitude}, lat: ${latitude}} representation

Utilizing this won't always be possible/easiest, so please at least adopt the following conventions. Any variables or functions that contain the following names should be represented by the accompanying structure:

  • latlon: {lon: ${longitude}, lat: ${latitude}}
  • coordinates: [${longitude}, ${latitude}]
  • point: {x: ${longitude}, y: ${latitude}}

If you must convert it to a string, put it in the following format:

  • '${longitude},${latitude}'

API

import assert from 'assert'
import ll from 'lonlng'

const lat = 38.13234
const lon = 70.01232
const latlon = {lat, lon}
const point = {x: lon, y: lat}
const coordinates = [lon, lat]
const str = `${lon},${lat}`

const pairs = [
  // normalization
  [latlon, ll(latlon)],
  [latlon, ll(point)],
  [latlon, ll(coordinates)],
  [latlon, ll(str)],

  // convert to type, normalizes to `latlng` first in each function
  [ll.toCoordinates(latlon), coordinates],
  [ll.toPoint(latlon), point],
  [ll.toString(latlon), str],

  // if the type is known, use the specific convert function directly
  [latlon, ll.fromLatlng(latlon)],
  [latlon, ll.fromCoordinates(coordinates)],
  [latlon, ll.fromPoint(point)],
  [latlon, ll.fromString(str)]
]

pairs.forEach(pair => assert.deepEqual(pair[0], pair[1]))

Keywords

FAQs

Package last updated on 29 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc