README
ember-location
A utility for working with geolocation in an Ember.js app.
Usage
Installation
ember install @abcum/ember-location
Methods
find()
The find
method retrives the location from the browser using the HTML5 Geolocation API. It returns a Ember.RSVP.Promise, which will reject if the HTML5 Geolocation API is not available, or if the current coordinates are not able to be found, and will resolve if the positioning was successful. In addition the current geolocation position is saved to the current
property.
this.get('location').find({ timeout:5000 }).then(function(result) {
// Access the user's location using `result` or `this.location.current`
});
It accepts an optional object as the first argument which can be used to customise the query. If omitted it will default to the values listed here.
{
enableHighAccuracy: false,
timeout: Infinity,
maximumAge: 0
}
watch()
The watch
method continually retrieves and tracks the location from the browser using the HTML5 Geolocation API. It returns a Ember.RSVP.Promise, which will reject if the HTML5 Geolocation API is not available, or if the current coordinates are not able to be found, and will resolve if the positioning was successful. In addition the current geolocation position is continually saved to the current
property.
this.get('location').watch({ timeout:5000 }).then(function(result) {
// Access the user's location using `result` or `this.location.current`
});
It accepts an optional object as the first argument which can be used to customise the query. If omitted it will default to the values listed here.
{
enableHighAccuracy: false,
timeout: Infinity,
maximumAge: 0
}
Properties
The current
property stores the latest positioning data which was retrieved using the HTML5 Geolocation API, an example of which is displayed here.
{
coords: {
accuracy: 75,
altitude: null,
altitudeAccuracy: null,
heading: null,
latitude: 51.165,
longitude: 0.248,
speed: null
},
timestamp: 1470156731858
}
Examples
Wait for the current position before displaying the route.
export default Ember.Route.extend({
model() {
return this.get('location').watch();
}
})
Display the current position on a map in the template using the current
object.
{{example-map lat=location.current.coords.latitude lng=location.current.coords.longitude}}
Development
make install
(install bower and ember-cli dependencies)make upgrade
(upgrade ember-cli to the specified version)make tests
(run all tests defined in the package)