Git Product home page Git Product logo

bscoords's Introduction

Description

Library to get location from mobile networks information (MCC, MNC, LAC, Cell ID) using Google, Yandex, OpenCellId, Mylnikov and Mozilla Location Services.

In this new version library was completely rewritten in pure JavaScript with Promises and no external dependencies.

All services now work fine, but for some of them you need API keys.

Installation

You can install it with this command:

npm install bscoords

Usage

First require library:

const bscoords = require('bscoords');

If you want to use OpenCellId, Mozilla Location Service or set custom socket timeout, you should initialize library before using:

bscoords.init({
    // API keys
    apikey_mylnikov  : '', // nicely works even without API key
    apikey_opencellid: 'you should sign up on https://opencellid.org/ to get this',
    apikey_mozilla   : 'you should request it at Mozilla',

    // socket timeout in milliseconds (default is 3000)
    'timeout': 3000
});

Then perform requests the following way:

bs
    .yandex(mcc, mnc, lac, cellid)
    .then(coords => {
        console.log(JSON.stringify(coords, null, 4));
    })
    .catch(err => console.log(err));

bs
    .google(mcc, mnc, lac, cellid)
    .then(coords => {
        console.log(JSON.stringify(coords, null, 4));
    })
    .catch(err => console.log(err));

bs
    .opencellid(mcc, mnc, lac, cellid)
    .then(coords => {
        console.log(JSON.stringify(coords, null, 4));
    })
    .catch(err => console.log(err));

bs
    .mylnikov(mcc, mnc, lac, cellid)
    .then(coords => {
        console.log(JSON.stringify(coords, null, 4));
    })
    .catch(err => console.log(err));

bs
    .mozilla(mcc, mnc, lac, cellid)
    .then(coords => {
        console.log(JSON.stringify(coords, null, 4));
    })
    .catch(err => console.log(err));

bs
    .cell2gps(mcc, mnc, lac, cellid)
    .then(coords => {
        console.log(JSON.stringify(coords, null, 4));
    })
    .catch(err => console.log(err));

// result of every call will be like this:
// {
//     "lat": 54.54321,
//     "lon": 23.12345
// }

You can also use one request to get coordinates from all services at once:

bs
    .all(mcc, mnc, lac, cellid)
    .then(coords => {
        console.log(`All:`);
        console.log(JSON.stringify(coords, null, 4));
    })
    .catch(err => {
        console.log(`All ERROR:`);
        console.log(err);
    });

Or you can explicitly choose services to get coordinates from:

bs
    .all(mcc, mnc, lac, cellid, ['yandex', 'google', 'mylnikov', 'opencellid', 'mozilla', 'cell2gps'])
    .then(coords => {
        console.log(`All:`);
        console.log(JSON.stringify(coords, null, 4));
    })
    .catch(err => {
        console.log(`All ERROR:`);
        console.log(err);
    });

You can also specify weight of every service to calculate average coordinates with respect of services accuracy.

In this example Yandex and Google are the most significant services in average coordinates calculation, Mylnikov.org is the least significant and Mozilla Location Service doesn't affects average coordinates at all:

bs
    .all(mcc, mnc, lac, cellid,
            ['yandex', 'google', 'mylnikov', 'opencellid', 'mozilla', 'cell2gps'],
            {yandex: 1, google: 1, mylnikov: 0.2, opencellid: 0.5, mozilla: 0, cell2gps: 1})
    .then(coords => {
        console.log(`All:`);
        console.log(JSON.stringify(coords, null, 4));
    })
    .catch(err => {
        console.log(`All ERROR:`);
        console.log(err);
    });

Result will be object with the following structure:

{
    // average coordinates from all services
    "average": {
        "lat": 54.54321,
        "lon": 23.12345
    },
    "yandex": {
        "lat": 54.54321,
        "lon": 23.12345
    },
    "google": {
        "lat": 54.54321,
        "lon": 23.12345
    },
    "mylnikov": {
        "lat": 54.54321,
        "lon": 23.12345
    },
    "opencellid": null, // no coordinates got from this service
    "mozilla": {
        "lat": 54.54321,
        "lon": 23.12345
    },
    "cell2gps": {
        "lat": 54.54321,
        "lon": 23.12345
    }
}

@license MIT
@version 2.1.0
@author Alexander Russkiy [email protected]

bscoords's People

Contributors

kolonist avatar mylnikovorg avatar vinerich avatar dependabot[bot] avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.