diff --git a/src/GeoLocationForPhoneGap/GeoLocationForPhoneGap.xml b/src/GeoLocationForPhoneGap/GeoLocationForPhoneGap.xml index 88788fa..e510a54 100644 --- a/src/GeoLocationForPhoneGap/GeoLocationForPhoneGap.xml +++ b/src/GeoLocationForPhoneGap/GeoLocationForPhoneGap.xml @@ -49,5 +49,15 @@ The nanoflow to call when the location has been retrieved + + High accuracy + Behavior + Provides a hint that the application needs the best possible results. By default, the device attempts to retrieve a Position using network-based methods. Setting this property to true tells the framework to use more accurate methods, such as satellite positioning. + + + Locate on load + Behavior + Automatically get the current location when the widget is loaded. + diff --git a/src/GeoLocationForPhoneGap/widget/GeoLocationForPhoneGap.js b/src/GeoLocationForPhoneGap/widget/GeoLocationForPhoneGap.js index b44be27..4766f98 100644 --- a/src/GeoLocationForPhoneGap/widget/GeoLocationForPhoneGap.js +++ b/src/GeoLocationForPhoneGap/widget/GeoLocationForPhoneGap.js @@ -39,6 +39,11 @@ define([ update: function(obj, callback) { this._obj = obj; + // If configured, automatically update geolocation + if (this.getPositionOnLoad) { + this._getCurrentPosition(); + } + if (callback) { callback(); } @@ -70,16 +75,18 @@ define([ // Internal event setup. _setupEvents: function() { - this.connect(this._button, "click", function(evt) { - console.log("GEO Location start getting location."); - - navigator.geolocation.getCurrentPosition( - this._geolocationSuccess.bind(this), - this._geolocationFailure.bind(this), { - timeout: 10000, - enableHighAccuracy: true - }); - }); + this.connect(this._button, "click", this._getCurrentPosition); + }, + + _getCurrentPosition: function() { + console.log("GEO Location start getting location."); + + navigator.geolocation.getCurrentPosition( + this._geolocationSuccess.bind(this), + this._geolocationFailure.bind(this), { + timeout: 10000, + enableHighAccuracy: this.enableHighAccuracy + }); }, _geolocationSuccess: function(position) {