{ "id": "123042", "key": "AC-2351", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "12217", "key": "AC", "name": "Appcelerator - INBOX", "projectCategory": { "id": "10000", "description": "", "name": "Customer Service" } }, "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2014-01-16T05:28:24.000+0000", "created": "2013-11-28T17:38:02.000+0000", "labels": [ "android" ], "versions": [], "issuelinks": [], "assignee": { "name": "shossain", "key": "shossain", "displayName": "Shak Hossain", "active": false, "timeZone": "America/Los_Angeles" }, "updated": "2016-03-08T07:41:22.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "14550", "name": "Appcelerator Modules", "description": "Please enter tickets related to Modules here." }, { "id": "14548", "name": "Titanium SDK & CLI", "description": "Please enter tickets related to the MobileSDK here." } ], "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.\r\n\r\n{code:title=Function Example |borderStyle=solid}\r\nexports.currentPosition = function() {\r\n\ttry {\r\n\t\tTitanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;\r\n\t\tTi.Geolocation.preferredProvider = Ti.Geolocation.PROVIDER_GPS;\r\n\t\tTitanium.Geolocation.distanceFilter = 10;\r\n\t\tif (Titanium.Geolocation.locationServicesEnabled === false) {\r\n\t\t\talert('Your device has GPS turned off. Please turn it on.');\r\n\t\t\treturn {\r\n\t\t\t\t'longitude' : 0,\r\n\t\t\t\t'latitude' : 0,\r\n\t\t\t\t'altitude' : 0,\r\n\t\t\t\t'heading' : 0,\r\n\t\t\t\t'accuracy' : 0,\r\n\t\t\t\t'speed' : 0,\r\n\t\t\t\t'timestamp' : 0,\r\n\t\t\t\t'altitudeAccuracy' : 0\r\n\t\t\t};\r\n\t\t}\r\n\t\tvar longitude, latitude, altitude, heading, accuracy, speed, timestamp, altitudeAccuracy;\r\n\t\tTitanium.Geolocation.getCurrentPosition(function(e) {\r\n\t\t\tif (!e.success || e.error) {\r\n\t\t\t\tvar msg = L('msgUnableLocation');\r\n\t\t\t\tTitanium.UI.createAlertDialog({\r\n\t\t\t\t\ttitle : L('titleAlertValidation'),\r\n\t\t\t\t\tmessage : String(msg),\r\n\t\t\t\t\tbuttonNames : [L('btnDone')]\r\n\t\t\t\t}).show();\r\n\t\t\t\treturn {\r\n\t\t\t\t\t'longitude' : 0,\r\n\t\t\t\t\t'latitude' : 0,\r\n\t\t\t\t\t'altitude' : 0,\r\n\t\t\t\t\t'heading' : 0,\r\n\t\t\t\t\t'accuracy' : 0,\r\n\t\t\t\t\t'speed' : 0,\r\n\t\t\t\t\t'timestamp' : 0,\r\n\t\t\t\t\t'altitudeAccuracy' : 0\r\n\t\t\t\t};\r\n\t\t\t}\r\n\t\t\tlongitude = e.coords.longitude;\r\n\t\t\tlatitude = e.coords.latitude;\r\n\t\t\taltitude = e.coords.altitude;\r\n\t\t\theading = e.coords.heading;\r\n\t\t\taccuracy = e.coords.accuracy;\r\n\t\t\tspeed = e.coords.speed;\r\n\t\t\ttimestamp = e.coords.timestamp;\r\n\t\t\taltitudeAccuracy = e.coords.altitudeAccuracy;\r\n\t\t});\r\n\t\treturn {\r\n\t\t\t'longitude' : longitude,\r\n\t\t\t'latitude' : latitude,\r\n\t\t\t'altitude' : altitude,\r\n\t\t\t'heading' : heading,\r\n\t\t\t'accuracy' : accuracy,\r\n\t\t\t'speed' : speed,\r\n\t\t\t'timestamp' : timestamp,\r\n\t\t\t'altitudeAccuracy' : altitudeAccuracy\r\n\t\t};\r\n\t\tlongitude = null;\r\n\t\tlatitude = null;\r\n\t\taltitude = null;\r\n\t\theading = null;\r\n\t\taccuracy = null;\r\n\t\tspeed = null;\r\n\t\ttimestamp = null;\r\n\t\taltitudeAccuracy = null;\r\n\t} catch( s_error ) {\r\n\t\tTitanium.UI.createAlertDialog({\r\n\t\t\ttitle : \"fields gps\",\r\n\t\t\tmessage : String(s_error),\r\n\t\t\tbuttonNames : ['OK']\r\n\t\t}).show();\r\n\t}\r\n}; \r\n{code} \r\n\r\nAnd then this function is called in a different place this way: \r\n{code}\r\n\tvar core= require('modules/core');\r\n\r\n\tformGeographic.addEventListener('maxGeoButton', function(e) {\r\n\t\tmaxAltitudePosition = core.currentPosition();\r\n\t\tvar fieldRefs = formGeographic.fieldRefs;\r\n\t fieldRefs['maxGeoButton'].setTitle(L('labelGPSPointWasTakenMax'));\r\n\t}); \r\n\r\n{code} \r\n\r\nHow can finish this function? because when I save the register, the application crashed, yes save the register but my app rebooted.", "attachment": [], "flagged": false, "summary": "Start and finish Titanium.Geolocation.getCurrentPosition", "creator": { "name": "mabs86`", "key": "mabs86`", "displayName": "Marian Bresol", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "mabs86`", "key": "mabs86`", "displayName": "Marian Bresol", "active": true, "timeZone": "America/Los_Angeles" }, "environment": "Titanium Studio, build: 3.1.3.201309132423\r\nTSdk: 3.1.3.GA\r\nAndroid", "comment": { "comments": [ { "id": "283038", "author": { "name": "morahman", "key": "morahman", "displayName": "Motiur Rahman", "active": true, "timeZone": "Asia/Dhaka" }, "body": "Hi Marian,\r\n\r\nYour 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. \r\n\r\nThanks \r\n", "updateAuthor": { "name": "shossain", "key": "shossain", "displayName": "Shak Hossain", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2013-12-07T08:54:09.000+0000", "updated": "2013-12-07T18:57:45.000+0000" }, { "id": "287718", "author": { "name": "mpmiranda", "key": "mpmiranda", "displayName": "Mauro Parra-Miranda", "active": true, "timeZone": "America/Mexico_City" }, "body": "Hello Marian, \r\n\r\nh4. Introduction\r\n\r\nI 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. \r\n\r\nh4. Test Case\r\n\r\nThis 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. \r\n\r\nh5. app.js\r\n\r\n{code}\r\nvar geo = require('geo');\r\n\r\nvar win = Ti.UI.createWindow({\r\n\tbackgroundColor:'white',\r\n});\r\nvar i =0; \r\nsetInterval(function(){\r\n\t\t\tTi.API.info(\"Function calls without crashing: \"+i++);\r\n\t\t\tgeo.currentPosition();\r\n\t\t\t\r\n},1000);\r\n\r\nwin.open();\r\n{code}\r\n\r\nh5. geo.js \r\n\r\n{code}\r\nvar init = false;\r\n\r\nfunction initGeo() {\r\n\tif (init == false) {\r\n\t\tTi.Geolocation.accuracy = Ti.Geolocation.ACCURACY_BEST;\r\n\t\tTi.Geolocation.preferredProvider = Ti.Geolocation.PROVIDER_GPS;\r\n\t\tTi.Geolocation.distanceFilter = 10;\r\n\t\tif (Titanium.Geolocation.locationServicesEnabled === false) {\r\n\t\t\talert('Your device has GPS turned off. Please turn it on.');\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tinit = true;\r\n\t}\r\n}\r\n\r\n//any property attached to the exports object becomes part of the module's public interface\r\nexports.currentPosition = function() {\r\n\tinitGeo();\r\n\tTitanium.Geolocation.getCurrentPosition(function(e) {\r\n\t\tif (!e.success || e.error) {\r\n\t\t\talert(\"Can't get the current position\");\r\n\t\t\treturn {\r\n\t\t\t\t'longitude' : 0,\r\n\t\t\t\t'latitude' : 0,\r\n\t\t\t\t'altitude' : 0,\r\n\t\t\t\t'heading' : 0,\r\n\t\t\t\t'accuracy' : 0,\r\n\t\t\t\t'speed' : 0,\r\n\t\t\t\t'timestamp' : 0,\r\n\t\t\t\t'altitudeAccuracy' : 0\r\n\t\t\t};\r\n\t\t} else {\r\n\t\t\t//alert(\"lon \" + e.coords.longitude + \" lat \" + e.coords.latitude);\r\n\t\t\tTi.API.info(\"lon \" + e.coords.longitude + \" lat \" + e.coords.latitude)\r\n\t\t\treturn {\r\n\t\t\t\t'longitude' : e.coords.longitude,\r\n\t\t\t\t'latitude' : e.coords.latitude,\r\n\t\t\t\t'altitude' : e.coords.altitude,\r\n\t\t\t\t'heading' : e.coords.heading,\r\n\t\t\t\t'accuracy' : e.coords.accuracy,\r\n\t\t\t\t'speed' : e.coords.speed,\r\n\t\t\t\t'timestamp' : e.coords.timestamp,\r\n\t\t\t\t'altitudeAccuracy' : e.coords.altitudeAccuracy,\r\n\t\t\t};\r\n\t\t}\r\n\t});\r\n};\r\n{code}\r\n\r\nh4. Testing environment\r\n\r\nMobile SDK 3.2.0\r\nAndroid 4.4 Kitkat\r\nNexus 4\r\n\r\nh4. Steps to test\r\n1. Create a new mobile project (classic titanium with 3.2.0.GA Mobile SDK)\r\n2. Paste the testcase in app.js and geo.js in the Resources directory.\r\n3. Run in device\r\n4. Check in the terminal for the number of times that the test has been run.\r\n\r\nh4. Analysis of the code\r\nIn 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. \r\n\r\nYour crashing might be related to configuring the GPS several times in short time. \r\n\r\nh4. Recommendations\r\n\r\nPlease modify the pattern on your commonjs module to mimic the init function, and then let us know if that helped you.\r\n\r\nBest,\r\n\r\nMauro", "updateAuthor": { "name": "shossain", "key": "shossain", "displayName": "Shak Hossain", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2014-01-10T22:16:25.000+0000", "updated": "2014-01-10T22:26:16.000+0000" }, { "id": "288416", "author": { "name": "shossain", "key": "shossain", "displayName": "Shak Hossain", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Marking this as resolved since the issue cannot be reproduced. We posted a functional sample that was tested extensibly to reproduce the crash scenario.", "updateAuthor": { "name": "shossain", "key": "shossain", "displayName": "Shak Hossain", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2014-01-16T05:28:24.000+0000", "updated": "2014-01-16T05:28:24.000+0000" } ], "maxResults": 4, "total": 4, "startAt": 0 } } }