Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions src/GeoLocationForPhoneGap/GeoLocationForPhoneGap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,15 @@
<description>The nanoflow to call when the location has been retrieved</description>
<returnType type="Void"/>
</property>
<property key="enableHighAccuracy" type="boolean" defaultValue="true">
<caption>High accuracy</caption>
<category>Behavior</category>
<description>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.</description>
</property>
<property key="getPositionOnLoad" type="boolean" defaultValue="false">
<caption>Locate on load</caption>
<category>Behavior</category>
<description>Automatically get the current location when the widget is loaded.</description>
</property>
</properties>
</widget>
27 changes: 17 additions & 10 deletions src/GeoLocationForPhoneGap/widget/GeoLocationForPhoneGap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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) {
Expand Down