mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-26 12:03:28 +08:00
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 object
s method since we can`t directly overwrite it.
This commit is contained in:
parent
0c585b7416
commit
5255f63237
4
droidgap
4
droidgap
@ -75,9 +75,9 @@ class Build
|
|||||||
Dir.chdir("#{ @dir }framework#{ @s }assets#{ @s }js")
|
Dir.chdir("#{ @dir }framework#{ @s }assets#{ @s }js")
|
||||||
basedir = "."
|
basedir = "."
|
||||||
js = Dir.new(basedir).entries
|
js = Dir.new(basedir).entries
|
||||||
phonegapjs = ""
|
phonegapjs = IO.read('phonegap.js.base');
|
||||||
js.each do |script|
|
js.each do |script|
|
||||||
next if script[0].chr == "."
|
next if script[0].chr == "." or script == "phonegap.js.base"
|
||||||
phonegapjs += IO.read(script)
|
phonegapjs += IO.read(script)
|
||||||
phonegapjs += "\n\n"
|
phonegapjs += "\n\n"
|
||||||
end
|
end
|
||||||
|
@ -14,46 +14,12 @@ function Geolocation() {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options)
|
||||||
* Asynchronously aquires the current position.
|
{
|
||||||
* @param {Function} successCallback The function to call when the position
|
var position = Geo.getCurrentLocation();
|
||||||
* data is available
|
this.global_success = successCallback;
|
||||||
* @param {Function} errorCallback The function to call when there is an error
|
this.fail = errorCallback;
|
||||||
* 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);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asynchronously aquires the position repeatedly at a given interval.
|
* Asynchronously aquires the position repeatedly at a given interval.
|
||||||
@ -111,23 +77,6 @@ Geolocation.prototype.setError = function(message) {
|
|||||||
f(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
|
// Run the global callback
|
||||||
Geolocation.prototype.gotCurrentPosition = function(lat, lng, alt, altacc, head, vel, stamp)
|
Geolocation.prototype.gotCurrentPosition = function(lat, lng, alt, altacc, head, vel, stamp)
|
||||||
@ -185,3 +134,16 @@ Geolocation.prototype.clearWatch = function(watchId)
|
|||||||
{
|
{
|
||||||
Geo.stop(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"]
|
||||||
|
);
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user