mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 07:02:51 +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")
|
||||
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
|
||||
|
@ -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);
|
||||
Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options)
|
||||
{
|
||||
var position = Geo.getCurrentLocation();
|
||||
this.global_success = successCallback;
|
||||
this.fail = errorCallback;
|
||||
}
|
||||
}, interval);
|
||||
};
|
||||
|
||||
/**
|
||||
* Asynchronously aquires the position repeatedly at a given interval.
|
||||
@ -112,23 +78,6 @@ Geolocation.prototype.setError = function(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"]
|
||||
);
|
||||
});
|
Loading…
Reference in New Issue
Block a user