From fbd36fd9046053beed36a5f54a5ee36c74af11cd Mon Sep 17 00:00:00 2001 From: torayeff Date: Thu, 18 Jun 2015 20:22:37 +0500 Subject: [PATCH] Geolocation options --- packages/mdg:geolocation/geolocation.js | 27 ++++++++++++------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/packages/mdg:geolocation/geolocation.js b/packages/mdg:geolocation/geolocation.js index 87616a6..ba7e06e 100644 --- a/packages/mdg:geolocation/geolocation.js +++ b/packages/mdg:geolocation/geolocation.js @@ -7,12 +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 -}; - var onError = function (newError) { error.set(newError); }; @@ -22,8 +16,13 @@ var onPosition = function (newLocation) { error.set(null); }; -var startWatchingPosition = function () { +var startWatchingPosition = function (options) { if (! watchingPosition && navigator.geolocation) { + options = options || { + enableHighAccuracy: true, + maximumAge: 0, + timeout: 10000 + }; navigator.geolocation.watchPosition(onPosition, onError, options); watchingPosition = true; } @@ -42,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(); }, @@ -53,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 @@ -64,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 { @@ -76,4 +75,4 @@ Geolocation = { return null; } -}; \ No newline at end of file +};