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 🙏

© 2026 – Pkg Stats / Ryan Hefner

geocoordarith

v0.0.6

Published

GeoCoordArith provides arithmetic on geo coordinates. 経緯度に関する計算モジュールです. 这模块提供简单的地理定位算法。

Readme

はじめに

Geocoordarithは経度緯度に基づいたさまざまな計算を行うためのライブラリです。

簡単な例

import { createLocation } from "geocoordarith/build/src/SimpleLocation"
import { getDistance, getMidpoint } from "geocoordarith/build/src/GeoCoords"

const TokyoStation = createLocation(35.681540, 139.767209)
const OsakaStation = createLocation(34.702776, 135.496090)
console.log(getDistance(TokyoStation, OsakaStation, 'km'))
// -> 403.5031624306115
const middle = getMidpoint(TokyoStation, OsakaStation))
console.log(middle.getLatitude(), middle.getLongitude())
// -> 35.21090841886774 137.61877971013595
// 注)長野県下伊那郡根羽村

インストール

最新版はnpmでインストールすることができます。

npm install geocoordarith

ドキュメント

GeoCoordinated

geocoordarithでの計算は経緯度を提供するインターフェースを実装するすべてのオブジェクトに対して行うことができます。

GeoCoordinatedインターフェースを実装するためには、緯度経度を度数法で与えるgetLatitude, getLongitudeと弧度法で与えるgetLatitudeInRad, getLongitudeInRadを実装する必要があります。

GeoCoordinatedインターフェースを実装するもっとも簡単なクラスはSimpleLocationです。ただ、new SimpleLocation(x, y)によってオブジェクトを作るのは推奨しません。代わりにcreateLocationでは、(度数法での)緯度経度で簡単にSimpleLocationオブジェクトを生成できます。

import { createLocation } from "geocoordarith/build/src/SimpleLocation"

const TokyoStation = createLocation(35.681540, 139.767209)

なお、new SimpleLocation(x, y)で直接オブジェクトを作る際には、自分で度数法と弧度法の変換に関する情報をunitconvを使って自分で実装する必要があります。

距離の計算

地球を半径6378.137KMの完全な球体と仮定して距離の計算を行うには、GeoCoords.getDistance関数を利用します。

/**
 * 地球を完全な球体と仮定して球面上の二点間の距離を計算する。
 * Returns the distance between x and y on the earth, assuming it is a perfect sphere.
 * @param x 
 * @param y 
 * @param unitName km, m, cm
 */
export declare function getDistance(x: GeoCoordinated, y: GeoCoordinated, unitName?: string): number;

unitNameは現在

  • km: キロメートル
  • m : メートル
  • cm: センチメートル

のみ対応しています。unitNameを指定しないときはメートルでの値を返します。

import { createLocation } from "geocoordarith/build/src/SimpleLocation"
import { getDistance } from "geocoordarith/build/src/GeoCoords"

const TokyoStation = createLocation(35.681540, 139.767209)
const OsakaStation = createLocation(34.702776, 135.496090)
console.log(getDistance(TokyoStation, OsakaStation, 'km'))
// -> 403.5031624306115

中点の計算

地球を半径6378.137KMの完全な球体と仮定して、二点の中点の計算を行うには、GeoCoords.getMidpoint関数を利用します。

/**
 * 地球を完全な球体と仮定して、二点の球面上の中点を求める。
 * Returns the midpoint between x and y on the earth, assuming it is a perfect sphere.
 * @param x 
 * @param y 
 */
export declare function getMidpoint(x: GeoCoordinated, y: GeoCoordinated): SimpleLocation;

import { createLocation } from "geocoordarith/build/src/SimpleLocation"
import { getMidpoint } from "geocoordarith/build/src/GeoCoords"

const TokyoStation = createLocation(35.681540, 139.767209)
const OsakaStation = createLocation(34.702776, 135.496090)
const middle = getMidpoint(TokyoStation, OsakaStation))
console.log(middle.getLatitude(), middle.getLongitude())
// -> 35.21090841886774 137.61877971013595