
Security News
GitHub Actions Checkout Now Blocks Risky pull_request_target Checkouts
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.
geocoordarith
Advanced tools
GeoCoordArith provides arithmetic on geo coordinates. 経緯度に関する計算モジュールです. 这模块提供简单的地理定位算法。
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
GeoCoordinatedgeocoordarithでの計算は経緯度を提供するインターフェースを実装するすべてのオブジェクトに対して行うことができます。
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は現在
のみ対応しています。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
FAQs
GeoCoordArith provides arithmetic on geo coordinates. 経緯度に関する計算モジュールです. 这模块提供简单的地理定位算法。
The npm package geocoordarith receives a total of 14 weekly downloads. As such, geocoordarith popularity was classified as not popular.
We found that geocoordarith demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.