开发者社区> 镜像站> NPM> spacetime-geo
spacetime-geo
determine a timezone from a lat/lng
Last updated a year ago by spencermountain .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install spacetime-geo 
SYNC missed versions from official npm registry.
lat/long ←→ timezone
npm install spacetime-geo

spacetime plugin for determining a timezone based on a point on the earth, and vice-versa.

this is really just a wrapper of tz-lookup by dark-sky - based on Evan Siroky's awesome boundary-builder work.

const spacetime = require('./src/index')
const geo = require('spacetime-geo')
//apply the plugin
spacetime.extend(geo)

//set a specific time somewhere
let s = spacetime('June 4 2018', 'Canada/Eastern').time('3:37pm')

//where is this timezone? (approx)
s.point()
//{ lat: 43.65, lng: -79.38 }

//go to a specific point (near paris)
s.in([48.7235, 1.9931])

s.timezone().name
//Europe/Paris
s.time()
//9:37pm

in the browser: 111kb (uncompressed)

<script src="https://unpkg.com/spacetime"></script>
<script src="https://unpkg.com/spacetime-geo"></script>
<script>
  spacetime.extend(spacetimeGeo)
  var d = spacetime.now()
  //in the suburbs of São Paulo..
  d.in({lat:-23.7201, lon:-46.9543})
  console.log(d.time())
</script>

spacetime-geo accepts other formats of geolocation too:

spacetime.now().in({lat:42.7235, lon:-73.6931})
spacetime.now().in('48.7235, 1.9931')

Caveats - .in()

timezone boundaries are very, very detailed things. In order to keep this library small, we've simplified the paths. This may produce some off-by-one errors, close to the boundaries, especially for jagged coasts, or complex political boundaries.

1091

You can always produce a more-detailed, and larger (<=130mb!) dataset using Evan Siroky's script.

Caveats - .point()

I made-up an arbitrary point for each IANA timezone using the most-populous city in each timezone, and not any fancy centroid-math. This is all pretty-subjective stuff, especially for timezones like Etc/GMT-9. It should be fine for, centering a map, but probably not for doing air-strikes.

See also

MIT

Current Tags

  • 1.2.0                                ...           latest (a year ago)

6 Versions

  • 1.2.0                                ...           a year ago
  • 1.1.0                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
  • 0.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 1
Last Day 0
Last Week 1
Last Month 1
Dependencies (2)
Dev Dependencies (9)
Dependents (1)