Socket
Book a DemoInstallSign in
Socket

mock-geolocation

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mock-geolocation

Mock for navigator.geolocation API

latest
Source
npmnpm
Version
1.0.11
Version published
Weekly downloads
3.4K
-17.24%
Maintainers
1
Weekly downloads
 
Created
Source

Mock-geolocation

Mock for navigator.geolocation.

Russian readme

Demo

var point = [54.980206086231, 82.898068362003];

geolocate.use();

navigator.geolocation.getCurrentPosition(function(position) {
  assert(position.coords.latitude).equal(point[0]);
  assert(position.coords.longitude).equal(point[1]);
});

geolocate.send({lat: point[0], lng: point[1]});

geolocate.restore();

Installation

Manually:

<script src="geolocate.js"></script>

From npm:

npm install mock-geolocation

As CommonJS or AMD module:

var geolocate = require('mock-geolocation');

API

.use()

Replace the native navigator.geolocation object

.restore()

Restore navigator.geolocation in original state

.send([options])

This method emulates the finding position after calling getCurrentPosition and watchPosition method. Updates position from options which may include the following parameters from positions.coords and timestamp.

navigator.geolocation.getCurrentPosition(function(position) {
  console.log(position);
});

geolocate.send({
  latitude: 50,
  longitude: 10,
  accuracy: 5,
  timestamp: 3000
});

/* {
  coords: {
    accuracy: 5,
    altitude: null
    altitudeAccuracy: null,
    heading: null,
    latitude: 50
    longitude: 10,
    speed: null
  },
  timestamp: 3000
} */

navigator.geolocation.getCurrentPosition(function(position) {
  console.log(position);
});

geolocate.send();

/* Show same position {
  coords: {
    accuracy: 5,
    altitude: null
    altitudeAccuracy: null,
    heading: null,
    latitude: 50
    longitude: 10,
    speed: null
  },
  timestamp: 3000
} */

.change(options)

Change current position and call success callback of watchPosition method. Updates position from options which may include the following parameters from positions.coords and timestamp.

navigator.geolocation.watchPosition(function(position) {
  console.log(position.coords.latitude + ', ' + position.coords.longitude);
});

geolocate.send();
// 54.9799, 82.89683699999999

geolocate.change({lat: 10, lng: 15});
// 10, 15

geolocate.change({lat: 25});
// 25, 15

.sendError([options])

Call error callback of getCurrentPosition method. options may include the parameters code and message.

.changeError([options])

Call error callback of watchPosition method. options may include the parameters code and message.

Keywords

geolocation

FAQs

Package last updated on 01 Sep 2015

Did you know?

Socket

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