npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-latlong

v1.0.1

Published

bradfitz/latlong wrapper for Node.js

Downloads

6

Readme

node-latlong

Get timezone ID (such as America/Los_Angeles) from coordinates (latitude, longitude).

node-latlong internally uses latlong-cli which is a executable of bradfitz/latlong.

blazingly fast

No external API call. You can even run its method synchronously. It takes just few milliseconds.

lightweight

TL;DR: It's about 2.4MB after install.

There are pre-built binary distributions of latlong-cli for some major platforms in the package but useless executables will be automatically deleted by postinstall npm script when you install node-latlong.

usage

as a Node.js module

$ npm install node-latlong
const getTimezoneByCoords = require('node-latlong');

// use Promise, async / await
try {
    const timezone = await getTimezoneByCoords(37.7833, -122.4167);
    // 'America/Los_Angeles'
} catch (err) {
    // handle error
}

// use callback
getTimezoneByCoords(37.7833, -122.4167, (err, result) => {
    if (err) {
        // handle error
    }
    console.log(result);
    // 'America/Los_Angeles'
});

const getTimezoneByCoordsSync = require('node-latlong/sync');
const timezone = getTimezoneByCoordsSync(37.485419, 126.894239);
// 'Asia/Seoul'

global cli-executable

$ npm install -g node-latlong
$ latlong-cli 37.485419 126.894239
> Asia/Seoul

Keep that in mind the result can be empty string when you run binary directly.

methods

getTimezoneByCoords(latitude: number, longitude: number, [callback: function]): Promise

If callback is provided, Promise always will be resolved without rejection.

getTimezoneByCoordsSync(latitude: number, longitude: number): string

It's synchronous version of getTimezoneByCoords. You can get this method by require('node-latlong/sync').

known issues / things to know

It throws error when the result is empty

The result of bradfitz/latlong can be empty string if the input is junk. In this case, node-latlong throws an error. You can check it by error.emptyResult (boolean).

getTimezoneByCoords(37.7833, -122.4167).catch(err => {
    if (err && err.emptyResult) {
        // throw error or pass it over with kindly tolerance
    }
})

Why I get Asia/Phnom_Penh with this coordinates?

This is an issue of bradfitz/latlong.

I got an error on install

node-latlong doesn't support this platform or processor architecture

-> Please make issue or pull request to add the pre-built binary distribution for your platform/architecture.