1.0.2 • Published 8 years ago

geoposition-to-object v1.0.2

Weekly downloads
60
License
MIT
Repository
github
Last release
8 years ago

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