Socket
Book a DemoInstallSign in
Socket

geoposition-to-object

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

geoposition-to-object

Turn an HTML5 Geoposition object into a regular object that can be serialized with JSON.stringify

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

geoposition-to-object

Turn an HTML5 Geoposition object into a regular object that can be serialized with JSON.stringify

Pairs well with geolocation-stream.

See also geoposition-to-geojson, a very similar module that coerces geoposition objects into a Mapbox and/or OpenStreetMap-ready format.

Why

When using the geolocation feature in browsers, the object you'll get back cannot be stringified:

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

// {}

This package exports a function that accepts a Geoposition and returns a plain javascript Object with all the same deep properties.

Installation

npm install geoposition-to-object --save

Usage

var objectify = require('geoposition-to-object')

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

// {
//   timestamp: '2016-07-20T21:50:03.183Z',
//   coords: {
//     accuracy: 26,
//     altitude: null,
//     altitudeAccuracy: null,
//     heading: null,
//     latitude: 38.792024999999995,
//     longitude: -104.8483681,
//     speed: null
//   }
// }

Tests

npm install
npm test

Dependencies

None

Dev Dependencies

  • tap-spec: Formatted TAP output like Mocha's spec reporter
  • tape: tap-producing test harness for node and browsers

License

MIT

Generated by package-json-to-readme

Keywords

geo

FAQs

Package last updated on 24 Jul 2016

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