All Projects → DaniilSydorenko → haversine-geolocation

DaniilSydorenko / haversine-geolocation

Licence: MIT license
Get distances between two points or get closest position to current point. Based on the Haversine Formula

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to haversine-geolocation

geodist
Golang package to compute the distance between two geographic latitude, longitude coordinates
Stars: ✭ 133 (+565%)
Mutual labels:  distance, geolocation, haversine
geo-query
WordPress plugin: Geo Query - Modify the WP_Query/WP_User_Query to support the geo_query parameter. Uses the Haversine SQL implementation by Ollie Jones. With a Rest API example and support for an existing custom table .
Stars: ✭ 63 (+215%)
Mutual labels:  distance, haversine-formula
laravel-geoly
Perform fast and efficient radius searches on your Laravel Eloquent models.
Stars: ✭ 25 (+25%)
Mutual labels:  distance, geolocation
geo
Geospatial primitives and algorithms for Crystal
Stars: ✭ 17 (-15%)
Mutual labels:  geolocation, haversine
Geolocation Python
Geolocation is simple google maps api for python users. This application allows you to get information about given location Application returns such information as: country, city, route/street, street number, reverse geocode, lat and lng, travel distance and time for a matrix of origins and destinations.
Stars: ✭ 77 (+285%)
Mutual labels:  distance, geolocation
go-coronanet
Go implementation of the Corona Network
Stars: ✭ 35 (+75%)
Mutual labels:  distance
FakeGPS
[NOT MAINTAINED] FakeGPS driver for Windows
Stars: ✭ 85 (+325%)
Mutual labels:  geolocation
fasterRaster
Faster raster processing using GRASS GIS
Stars: ✭ 18 (-10%)
Mutual labels:  distance
totalopenstation
Total Open Station downloads and exports survey data from your total station
Stars: ✭ 51 (+155%)
Mutual labels:  geolocation
lala
🌎 Analyze and generate reports of web logs (NGINX)
Stars: ✭ 59 (+195%)
Mutual labels:  geolocation
captAR
Augmented Reality Geolocation Capture-the-Flag Mobile Game Capstone Project
Stars: ✭ 24 (+20%)
Mutual labels:  geolocation
ip2location-csv-converter
This PHP script converts IP2Location CSV database into IP range or CIDR format.
Stars: ✭ 26 (+30%)
Mutual labels:  geolocation
distance
Go lib to calculate distance 🗺
Stars: ✭ 16 (-20%)
Mutual labels:  distance
tinygeoip
🐉 tiny geoip microservice
Stars: ✭ 13 (-35%)
Mutual labels:  geolocation
geodesy-php
Geodesy PHP - Port of some known geodesic/math functions for getting distance from a known point A to a known point B given their coordinates. It also supports conversion between units of length, Polar position to Cartesian coordinates, and different Reference Datums.
Stars: ✭ 26 (+30%)
Mutual labels:  distance
wifi-locate
Locates your Wi-Fi-enabled machine using Wi-Fi access points signal strengths, using Google's API
Stars: ✭ 20 (+0%)
Mutual labels:  geolocation
svelte-googlemaps
Svelte Google Maps Components
Stars: ✭ 62 (+210%)
Mutual labels:  geolocation
df-aggregator
Networked DFing software that can handle multiple DOA receivers.
Stars: ✭ 47 (+135%)
Mutual labels:  geolocation
radiocells-nlp-android
radiocells.org Unified Network Location Provider
Stars: ✭ 35 (+75%)
Mutual labels:  geolocation
ember-cli-geo
Geolocation service for Ember.js web apps
Stars: ✭ 48 (+140%)
Mutual labels:  geolocation

Haversine-Geolocation

NPM

License: MIT Travis CI

Introduction

If you need to calculate the distance between two points or you want to find closest from position to your current location let me introduce haversine-geolocation module. It based on the Haversine Formula:

haversine

Formula

haversine_2

Pseudocode

dlon = lon2 - lon1 
dlat = lat2 - lat1 
a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2 
c = 2 * atan2( sqrt(a), sqrt(1-a) ) 
d = R * c (where R is the radius of the Earth)

R = 6367 km OR 3956 mi

Installation

npm i haversine-geolocation -S

Basic usage

Importing:

import HaversineGeolocation from 'haversine-geolocation';

API:

Is geolocation available:

Promise

HaversineGeolocation.isGeolocationAvailable()
    .then(data => {
        const currentPoint = {
            latitude: data.coords.latitude,
            longitude: data.coords.longitude,
            accuracy: data.coords.accuracy
        };
    });

Async await

	(async () => {
        const data = await HaversineGeolocation.isGeolocationAvailable();
        const currentPoint = {
            latitude: data.coords.latitude,
            longitude: data.coords.longitude,
            accuracy: data.coords.accuracy
        };
	})();

Calculate distance between two points:

const points = [
    {
        latitude: 61.5322204,
        longitude: 28.7515963
    },
    {
        latitude: 51.9971208,
        longitude: 22.1455439
    }
];
 
// Distance in miles
HaversineGeolocation.getDistanceBetween(points[0], points[1], 'mi'); // 704.1 mi
 
// Distance in meters
HaversineGeolocation.getDistanceBetween(points[0], points[1], 'm'); // 1133062.7 m
 
// Distance in kilometers(default value)
HaversineGeolocation.getDistanceBetween(points[0], points[1]); // 1133.1 km

Calculate the closest position to user:

Will return all existed properties with a small nested object haversine: { distance: val, measurement: 'val' }

const locationPoints = [
    {
        id: 1,
        title: 'Point 1',
        latitude: 61.5322204,
        longitude: 28.7515963
    },
    {
        id: 2,
        title: 'Point 2',
        latitude: 51.9971208,
        longitude: 22.1455439
    },
    {
        id: 3,
        title: 'Point 3',
        latitude: 45.3571207,
        longitude: 30.3435456
    }
];
 
HaversineGeolocation.isGeolocationAvailable()
    .then(data => {
        const currentPoint = {
            latitude: data.coords.latitude,
            longitude: data.coords.longitude,
            accuracy: data.coords.accuracy
        };
        
        HaversineGeolocation.getClosestPosition(
            currentPoint, 
            locationPoints,
            'mi'
        );
    });

Expected response:

    {
        "id": 3,
        "title": "Point 3",
        "latitude": 45.3571207,
        "longitude": 30.3435456,
        "haversine": {
            "distance": 49,
            "measurement": "mi"
        }
    }

License

The MIT License (MIT)

Copyright (c) 2020 Daniil Sydorenko

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].