Skip to content

max-mapper/geolocation-stream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

geolocation-stream

geolocation-stream is a node module that lets you use the HTML5 Geolocation API to watch location changes the node way -- with streams! It's designed for use with browserify.

Installation

npm install geolocation-stream --save

Usage

In this example, movement is a readable stream that speaks stream events: data, error and end. That means you can pipe movement output to anything that accepts streams, such as an XHR. in this case the data events will be lat/lon position updates using the watchPosition part of HTML5 geolocation.

var movement = require('geolocation-stream')()

movement.on('data', function(data) {
  console.log(data)
})

movement.on('error', function(err) {
  console.error(err)
})

Bundle it up into a browser-friendly file:

npm install browserify -g
browserify src.js -o bundle.js

Demo

Your browser's Geolocation API may not work with the file:// protocol, so you can't just pop open demo/index.html in your browser. Instead you'll need to run an HTTP server locally. Luckily that's not so hard:

cd geolocation-stream
npm install
npm start

Open localhost:9966 in your browser and open the Javascript console. Behold your geolocation stream! It should look something like this:

{
  timestamp:1383203179029,
  coords:{
    speed:null,
    heading:null,
    altitudeAccuracy:null,
    accuracy:28,
    altitude:null,
    longitude:-122.4236727,
    latitude:37.752089
  }
}

License

MIT

About

get HTML5 geolocation location changes as a node style stream

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published