All Projects → igorpreston → ember-cli-geo

igorpreston / ember-cli-geo

Licence: MIT license
Geolocation service for Ember.js web apps

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to ember-cli-geo

ember-link-action
Fire an action when LinkTo component transition happens
Stars: ✭ 86 (+79.17%)
Mutual labels:  ember-cli, ember, ember-cli-addon
Ember Cli Eslint
Ember CLI addon for linting Ember projects with ESLint
Stars: ✭ 116 (+141.67%)
Mutual labels:  ember-cli, ember
Ember Cli Stripe
Stripe checkout for Ember
Stars: ✭ 84 (+75%)
Mutual labels:  ember-cli, ember
Ember Cli Pace
Pace.js load progress bar for Ember apps, incl. Flash-like initial script lazy loading
Stars: ✭ 128 (+166.67%)
Mutual labels:  ember-cli, ember
Ember Simple Auth Auth0
Auth0 + lock.js, built on ember-simple-auth
Stars: ✭ 53 (+10.42%)
Mutual labels:  ember-cli, ember
Ember Cli Coffeescript
Adds precompilation of CoffeeScript files and all the basic generation types to the ember generate command.
Stars: ✭ 72 (+50%)
Mutual labels:  ember-cli, ember
ember-cli-qunit
QUnit testing package for ember-cli applications
Stars: ✭ 29 (-39.58%)
Mutual labels:  ember-cli, ember
Sharedrop
Easy P2P file transfer powered by WebRTC - inspired by Apple AirDrop
Stars: ✭ 5,222 (+10779.17%)
Mutual labels:  ember-cli, ember
Ember Cli Mocha
Mocha and Chai tests for ember-cli applications
Stars: ✭ 147 (+206.25%)
Mutual labels:  ember-cli, ember
Ember Cli Notifications
⚛ Atom inspired notification messages for ember-cli
Stars: ✭ 168 (+250%)
Mutual labels:  ember-cli, ember
Intellij Emberjs
Ember.js support for JetBrains IDEs (IntelliJ, WebStorm, ...)
Stars: ✭ 202 (+320.83%)
Mutual labels:  ember-cli, ember
Ember Cli Updater
ember-cli addon to help you update your ember-cli application or addon.
Stars: ✭ 32 (-33.33%)
Mutual labels:  ember-cli, ember
Mber
Fast and minimal Ember.js CLI alternative, without broccoli.
Stars: ✭ 30 (-37.5%)
Mutual labels:  ember-cli, ember
Ember Cli Bundle Analyzer
Analyze the size and contents of your Ember app's bundles
Stars: ✭ 78 (+62.5%)
Mutual labels:  ember-cli, ember
Rfcs
RFCs for changes to Ember
Stars: ✭ 731 (+1422.92%)
Mutual labels:  ember-cli, ember
Ember Tether
Tether an element to another element in the DOM
Stars: ✭ 116 (+141.67%)
Mutual labels:  ember-cli, ember
ember-cli-nouislider
{{range-slider}} component for ember-cli powered by noUiSlider
Stars: ✭ 43 (-10.42%)
Mutual labels:  ember-cli, ember
Ember Infinity
⚡️ Simple, flexible Infinite Scroll for Ember CLI Apps.
Stars: ✭ 368 (+666.67%)
Mutual labels:  ember-cli, ember
Ember Engines
Composable Ember applications for ambitious user experiences
Stars: ✭ 484 (+908.33%)
Mutual labels:  ember-cli, ember
Ember Web App
NOTICE: official repository moved to https://github.com/zonkyio/ember-web-app
Stars: ✭ 143 (+197.92%)
Mutual labels:  ember-cli, ember

ember-cli-geo

Code Climate Build Status

This addon is a go-to solution for integrating HTML5 Geolocation API into your Ember.js web app. It is production-ready and backwards compatible.

Installation

ember install ember-cli-geo

Usage

getLocation()

getLocation() gets user location from the browser and writes its coordinates to currentLocation property on the service. Accepts geoOptions as an argument. Returns an Ember.RSVP.Promise which is either resolved with geoObject containing all data about user location or is rejected with reason which explains why geolocation failed. It is used like this:

this.get('geolocation').getLocation().then(function(geoObject) {
  // do anything with geoObject here
  // you can also access currentLocation property and manipulate its data however you like
});

It corresponds to getCurrentPosition() in HTML5 Geolocation API. Learn more at getCurentPosition() on MDN. It emits an event geolocationSuccess with an object describing the geolocation when the position is available. If it fails, it emits an event geolocationFail with a reason.

trackLocation()

trackLocation() gets user location and setups a watcher which observes any changes occuring to user location. It then constantly updates currentLocation with the most recent location coordinates.

It accepts geoOptions as an argument. Returns an Ember.RSVP.Promise which is either resolved with geoObject containing all data about user location or is rejected with reason which explains why geolocation failed. It accepts an optional callback function, that is called whenever the position is updated. It emits an event geolocationSuccess with an object describing the geolocation whenever a new position is available. If it fails, it emits an event geolocationFail with a reason.

It is used like this:

this.get('geolocation').trackLocation().then(function(geoObject) {
  // do anything with geoObject here
  // currentLocation is constantly updated if user location is changed
});
// or
this.get('geolocation').trackLocation(null, (geoObject) => { /* will be called with new positiond */ })
// or
const service = this.get('geolocation');
service.on('geolocationSuccess', (geoObject) => { { /* will be called with new position */);

It corresponds to watchPosition() in HTML5 Geolocation API. Learn more at watchPosition() on MDN.

stopTracking

stopTracking() stops the app from continuously updating the user location.

It accepts an optional boolean parameter that clears currentLocation if it's true.

It is used like this:

this.get('geolocation').stopTracking(true);

It corresponds to watchPosition() in HTML5 Geolocation API. Learn more at clearWatch() on MDN.

currentLocation

currentLocation is a property of geolocation service which stores the array of user location coordinates in the format of [lat, lon]. It is used like this:

this.get('geolocation').get('currentLocation');

geoObject

geoObject is an object which contains all data about user location. Both getLocation() and trackLocation() promises are resolved with it. It looks like this:

{
  coords: {
    accuracy: 100,
    altitude: 0,
    altitudeAccuracy: 0,
    heading: NaN,
    latitude: 37.789,
    longitude: -122.412,
    speed: NaN
  },
  timestamp: 1435861233751
}

It corresponds to Position object in HTML5 Geolocation API. Learn more at Position object on MDN.

reason

reason is an error object which contains data about why geolocation has failed. Both getLocation() and trackLocation() promises are rejected with it. It corresponds to PositionError object in HTML5 Geolocation API. Learn more at PositionError object on MDN.

geoOptions

geoOptions is an optional object that can be passed to both getLocation() and trackLocation() to customize geolocation query. If you didn't pass it to functions, then next defaults will be automatically passed:

{
  enableHighAccuracy: false,
  timeout: Infinity,
  maximumAge: 0
}

It corresponds to PositionOptions object in HMTL5 Geolocation API. Learn more at PositionOptions object on MDN.

Usage Examples

Setup geolocation service

In order to use geolocation inside of your Ember.Route you should directly inject it to the one:

export default Ember.Route.extend({
  geolocation: Ember.inject.service()
});

Get user location and display it in your template

You need to implement a custom action which will call the geolocation service. In your route:

// app/routes/geolocator.js

export default Ember.Route.extend({

  actions: {
    getUserLocation: function() {
      this.get('geolocation').getLocation().then(function(geoObject) {
        var currentLocation = this.get('geolocation').get('currentLocation');
        this.controllerFor('geolocator').set('userLocation', currentLocation);
      });
    }
  }
});

In your controller:

// app/controllers/geolocator.js

export default Ember.Controller.extend({
  userLocation: null
});

In your template:

// app/templates/geolocator.hbs

<button type="button" {{action 'getUserLocation'}}>Geolocate me!</button>
{{#if userLocation}}
  {{userLocation}}
{{/if}}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].