Fixed building of phonegap.js in build script. Fixed GPS on Android 2.0+ - I guess they updated the version of WebKit being used on Android (similar now to how it works on iPhone) and thus the browser has a native navigator.geolocation object. Employed Jesses approach to proxying an objects method since we can`t directly overwrite it.

This commit is contained in:
filmaj 2010-02-13 17:09:02 -08:00
parent 0c585b7416
commit 5255f63237
2 changed files with 21 additions and 59 deletions

View File

@ -75,9 +75,9 @@ class Build
Dir.chdir("#{ @dir }framework#{ @s }assets#{ @s }js")
basedir = "."
js = Dir.new(basedir).entries
phonegapjs = ""
phonegapjs = IO.read('phonegap.js.base');
js.each do |script|
next if script[0].chr == "."
next if script[0].chr == "." or script == "phonegap.js.base"
phonegapjs += IO.read(script)
phonegapjs += "\n\n"
end

View File

@ -14,46 +14,12 @@ function Geolocation() {
};
};
/**
* Asynchronously aquires the current position.
* @param {Function} successCallback The function to call when the position
* data is available
* @param {Function} errorCallback The function to call when there is an error
* getting the position data.
* @param {PositionOptions} options The options for getting the position data
* such as timeout.
*/
Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options) {
var referenceTime = 0;
if (this.lastPosition)
referenceTime = this.lastPosition.timeout;
else
this.start(options);
var timeout = 20000;
var interval = 500;
if (typeof(options) == 'object' && options.interval)
interval = options.interval;
if (typeof(successCallback) != 'function')
successCallback = function() {};
if (typeof(errorCallback) != 'function')
errorCallback = function() {};
var dis = this;
var delay = 0;
var timer = setInterval(function() {
delay += interval;
if (typeof(dis.lastPosition) == 'object' && dis.lastPosition.timestamp > referenceTime) {
successCallback(dis.lastPosition);
clearInterval(timer);
} else if (delay >= timeout) {
errorCallback();
clearInterval(timer);
}
}, interval);
};
Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options)
{
var position = Geo.getCurrentLocation();
this.global_success = successCallback;
this.fail = errorCallback;
}
/**
* Asynchronously aquires the position repeatedly at a given interval.
@ -111,23 +77,6 @@ Geolocation.prototype.setError = function(message) {
f(message);
}
};
PhoneGap.addConstructor(function() {
if (typeof navigator.geolocation == "undefined") navigator.geolocation = new Geolocation();
});
/*
* Since we can't guarantee that we will have the most recent, we just try our best!
*
* Also, the API doesn't specify which version is the best version of the API
*/
Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options)
{
var position = Geo.getCurrentLocation();
this.global_success = successCallback;
this.fail = errorCallback;
}
// Run the global callback
Geolocation.prototype.gotCurrentPosition = function(lat, lng, alt, altacc, head, vel, stamp)
@ -185,3 +134,16 @@ Geolocation.prototype.clearWatch = function(watchId)
{
Geo.stop(watchId);
}
// Taken from Jesse's geo fix (similar problem) in PhoneGap iPhone. Go figure, same browser!
function __proxyObj(origObj, proxyObj, funkList) {
for (var v in funkList) {
origObj[funkList[v]] = proxyObj[funkList[v]];
}
}
PhoneGap.addConstructor(function() {
navigator._geo = new Geolocation();
__proxyObj(navigator.geolocation, navigator._geo,
["setLocation", "getCurrentPosition", "watchPosition",
"clearWatch", "setError", "start", "stop", "gotCurrentPosition"]
);
});