Socket
Socket
Sign inDemoInstall

@mmit/latlong

Package Overview
Dependencies
4
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mmit/latlong

Lightweight library for common latitude and longitude calculation


Version published
Maintainers
1
Weekly downloads
48
increased by50%

Weekly downloads

Readme

Source

LatLong - Lightweight library for common latitude and longitude calculation

Live-Example | GitHub-Home

This library supports both, the "Haversine" and the "Vincenty" algorithm.

"Haversine" is a bit faster but "Vincenty" is far more accurate!

LatLong

Catmull-Rom algorithm is used for smoothing out the path.

Basic usage

Distance

    const distance = new Distance();
    
    // km = 423
    const km = distance.as(LengthUnit.Kilometer,
     new LatLng(52.518611,13.408056),new LatLng(51.519475,7.46694444));
    
    // meter = 422591.551
    const meter = distance.distance(
        new LatLng(52.518611,13.408056),
        new LatLng(51.519475,7.46694444)
        );

Offset

    const distance = new Distance();
    const distanceInMeter = Math.round(EARTH_RADIUS * Math.PI / 4));
    
    const p1 = new LatLng(0.0, 0.0);
    const p2 = distance.offset(p1, distanceInMeter, 180);
    
    // LatLng(latitude:-45.219848, longitude:0.0)
    console.log(p2.round());
    
    // 45° 13' 11.45" S, 0° 0' 0.00" O
    console.log(p2.toSexagesimal());
            

Path smoothing

    // zigzag is a list of coordinates
    const path = new Path.from(zigzag);
    
    // Result is below
    const steps = path.equalize(8,smoothPath: true);

Smooth path

For more - check out my tests

Keywords

FAQs

Last updated on 25 Sep 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc