Giter Site home page Giter Site logo

mobile-locator's Introduction

Mobile Locator

NPM version MIT License Build Status Dependency Status Coverage Status NPM

Get geolocation from cell tower information.

Currently, the following APIs are implemented:

API

mobileLocator.createEngine(name, options)

Create the location engine by given name and options.

Name Options
google key: Google API key
mozilla key: Mozilla API key
opencellid key: OpenCellID API key
yandex key: Yandex API key
mylnikov
cellocation system(optional): Coordinate system: wgs84(Default), gcj02, bd09.
gpsspg key: GPSspg API key,
oid: GPSspg OID,
system(optional): Coordinate system: 0:wgs84_(Default)_; 1:gcj02; 2:bd09; 3:QQ Maps; 4:MapBar
haoservice key: HaoService API key,
system(optional): Coordinate system: 0: gcj02; 1:bd09; 2:wgs84_(Default)_

engine.locate(info, callback)

info should contain cell information, including mnc, mcc, lac and cid.

The callback is a function with 2 arguments: error and location. error should be null if everything is working, other wise the error message will be in the error argument.

location is an object contains following properties:

Property Description
longitude Longitude
latitude Latitude
accuracy The accuracy range of the given position
address(optional) For some API, this property contains the human readable address line.

Usage

Command-line Interface

Usage

~ mobile-locator -h

Usage: mobile-locator [options]

Locate geolocation information based on Cell base station data

Options:

  -h, --help                   output usage information
  -V, --version                output the version number
  -c, --cell <cell>            Cell tower base station information in format "MCC,MNC,LAC,CID". "-c 460,0,4219,20925"
  -e, --engine <engine>        Geolocation service engine. {google, mozilla, opencellid, yandex, mylnikov, cellocation, gpsspg, haoservice}. Default: google
  -a, --arguments <arguments>  Arguments for geolocation engine. e.g. "key:XXX,oid:123".
  -m, --map <map>              Map service. {google, bing, openstreetmap, google.cn, bing.cn, baidu}.
  -v, --verbose                Verbose output.

Examples:

  $ mobile-locator -a "key:XXX" -c 460,0,4219,20925
  $ mobile-locator -e cellocation -a "system:bd09" -m baidu -c 460,0,4219,20925

By default, the Google Geolocation engine will be used.

~ mobile-locator -a "key:GOOGLE_API_KEY" -c 460,0,4219,20925
{"longitude":116.46679499999998,"latitude":39.9910226,"accuracy":606}

With verbose option:

~ mobile-locator -a "key:AIzaSyAL2sfTLqUv9Rb3ercbtuu__PG2pS_4eDo" -c 460,0,4219,20925 -v
Geolocation engine: "google"
Cell: {"mcc":"460","mnc":"0","lac":"4219","cid":"20925"}
Location: {"longitude":116.46679499999998,"latitude":39.9910226,"accuracy":606}

More complex example:

  • Use cellocation engine;
  • Choose bd09 coordinate system;
  • Show Baidu map url for given coordinate;
  • Verbose output.
~ mobile-locator -e cellocation -a 'system:bd09' -m baidu -v -c 460,0,4219,20925
Geolocation engine: "cellocation"
Cell: {"mcc":"460","mnc":"0","lac":"4219","cid":"20925"}
Location: {"longitude":"116.479653","latitude":"39.997967","accuracy":"100","address":"北京市朝阳区望京街道望京园402号楼;广顺南大街与阜安西路路口东北109米"}
Map url: http://api.map.baidu.com/marker?location=39.997967,116.479653&title=_&content=北京市朝阳区望京街道望京园402号楼;广顺南大街与阜安西路路口东北109米&output=html&autoOpen=true

Use the library

const locator = require('./mobile-locator').locator;

const engine = locator.createEngine('google', {
  key: YOUR_GOOGLE_API_KEY,
});
engine.locate({
  mcc: 460,
  mnc: 0,
  lac: 4219,
  cid: 20925,
}, (error, location) => {
  if (error) {
    console.error(error);
  }
  console.log(location);
});

The output would be:

{ longitude: 116.46679499999998,
  latitude: 39.9910226,
  accuracy: 606 }

mobile-locator's People

Contributors

twang2218 avatar

Watchers

James Cloos avatar  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.