[AC-2351] Start and finish Titanium.Geolocation.getCurrentPosition
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2014-01-16T05:28:24.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Appcelerator Modules, Titanium SDK & CLI |
Labels | android |
Reporter | Marian Bresol |
Assignee | Shak Hossain |
Created | 2013-11-28T17:38:02.000+0000 |
Updated | 2016-03-08T07:41:22.000+0000 |
Description
My application use the the device's gps, and it works of this way, I make a function where {noformat} Titanium.Geolocation.getCurrentPosition {noformat} is called in different parts of my app.
exports.currentPosition = function() {
try {
Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
Ti.Geolocation.preferredProvider = Ti.Geolocation.PROVIDER_GPS;
Titanium.Geolocation.distanceFilter = 10;
if (Titanium.Geolocation.locationServicesEnabled === false) {
alert('Your device has GPS turned off. Please turn it on.');
return {
'longitude' : 0,
'latitude' : 0,
'altitude' : 0,
'heading' : 0,
'accuracy' : 0,
'speed' : 0,
'timestamp' : 0,
'altitudeAccuracy' : 0
};
}
var longitude, latitude, altitude, heading, accuracy, speed, timestamp, altitudeAccuracy;
Titanium.Geolocation.getCurrentPosition(function(e) {
if (!e.success || e.error) {
var msg = L('msgUnableLocation');
Titanium.UI.createAlertDialog({
title : L('titleAlertValidation'),
message : String(msg),
buttonNames : [L('btnDone')]
}).show();
return {
'longitude' : 0,
'latitude' : 0,
'altitude' : 0,
'heading' : 0,
'accuracy' : 0,
'speed' : 0,
'timestamp' : 0,
'altitudeAccuracy' : 0
};
}
longitude = e.coords.longitude;
latitude = e.coords.latitude;
altitude = e.coords.altitude;
heading = e.coords.heading;
accuracy = e.coords.accuracy;
speed = e.coords.speed;
timestamp = e.coords.timestamp;
altitudeAccuracy = e.coords.altitudeAccuracy;
});
return {
'longitude' : longitude,
'latitude' : latitude,
'altitude' : altitude,
'heading' : heading,
'accuracy' : accuracy,
'speed' : speed,
'timestamp' : timestamp,
'altitudeAccuracy' : altitudeAccuracy
};
longitude = null;
latitude = null;
altitude = null;
heading = null;
accuracy = null;
speed = null;
timestamp = null;
altitudeAccuracy = null;
} catch( s_error ) {
Titanium.UI.createAlertDialog({
title : "fields gps",
message : String(s_error),
buttonNames : ['OK']
}).show();
}
};
And then this function is called in a different place this way:
var core= require('modules/core');
formGeographic.addEventListener('maxGeoButton', function(e) {
maxAltitudePosition = core.currentPosition();
var fieldRefs = formGeographic.fieldRefs;
fieldRefs['maxGeoButton'].setTitle(L('labelGPSPointWasTakenMax'));
});
How can finish this function? because when I save the register, the application crashed, yes save the register but my app rebooted.
Hi Marian, Your exports function looks good. But we are missing some pieces of information that make it difficult for us to reproduce it. For reproducing this issue please provide us a full test case and steps to reproduce. Thanks
Hello Marian,
Introduction
I checked on your code, and created a simple test case for this. In the testing of the testcase, I have been calling a similar function for 4500 times, without crashing so far.Test Case
This testcase is in two files. App.js that contains the main file calling the commonjs module and the commonjs module. Both files will be in the Resources directory.app.js
geo.js
Testing environment
Mobile SDK 3.2.0 Android 4.4 Kitkat Nexus 4Steps to test
1. Create a new mobile project (classic titanium with 3.2.0.GA Mobile SDK) 2. Paste the testcase in app.js and geo.js in the Resources directory. 3. Run in device 4. Check in the terminal for the number of times that the test has been run.Analysis of the code
In your original code you are setting up the GPS in every single call. With the commonjs you can put the configuration as internal function (only doing something if is the first time you are configuring the commonjs module, doing nothing otherwise) and the shared function similar to yours. Your crashing might be related to configuring the GPS several times in short time.Recommendations
Please modify the pattern on your commonjs module to mimic the init function, and then let us know if that helped you. Best, MauroMarking this as resolved since the issue cannot be reproduced. We posted a functional sample that was tested extensibly to reproduce the crash scenario.