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 = ; // use Promise, async / awaittry const timezone = await ; // 'America/Los_Angeles' catch err // handle error // use callback; const getTimezoneByCoordsSync = ;const timezone = ;// '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
).
Asia/Phnom_Penh
with this coordinates?
Why I get 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.