Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extending startWatchingPosition for custom options #65

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions packages/mdg:geolocation/geolocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ var location = new ReactiveVar(null);
// error variable and dependency
var error = new ReactiveVar(null);

// options for watchPosition
var options = {
enableHighAccuracy: true,
maximumAge: 0,
timeout: 10000
};

var onError = function (newError) {
error.set(newError);
};
Expand All @@ -23,9 +16,14 @@ var onPosition = function (newLocation) {
error.set(null);
};

var startWatchingPosition = function () {
var startWatchingPosition = function (options) {
var params = {
enableHighAccuracy: options.enableHighAccuracy || true,
maximumAge: options.maximumAge || 0,
timeout: options.timeout || 10000
};
if (! watchingPosition && navigator.geolocation) {
navigator.geolocation.watchPosition(onPosition, onError, options);
navigator.geolocation.watchPosition(onPosition, onError, params);
watchingPosition = true;
}
};
Expand All @@ -43,8 +41,8 @@ Geolocation = {
* [position error](https://developer.mozilla.org/en-US/docs/Web/API/PositionError)
* that is currently preventing position updates.
*/
error: function () {
startWatchingPosition();
error: function (options) {
startWatchingPosition(options);
return error.get();
},

Expand All @@ -54,8 +52,8 @@ Geolocation = {
* [position](https://developer.mozilla.org/en-US/docs/Web/API/Position)
* that is reported by the device, or null if no position is available.
*/
currentLocation: function () {
startWatchingPosition();
currentLocation: function (options) {
startWatchingPosition(options);
return location.get();
},
// simple version of location; just lat and lng
Expand All @@ -65,8 +63,8 @@ Geolocation = {
* @return {Object | null} An object with `lat` and `lng` properties,
* or null if no position is available.
*/
latLng: function () {
var loc = Geolocation.currentLocation();
latLng: function (options) {
var loc = Geolocation.currentLocation(options);

if (loc) {
return {
Expand Down