Advertisement
Guest User

Untitled

a guest
Feb 12th, 2012
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.75 KB | None | 0 0
  1. // Create variable "win" to refer to current window
  2. var win = Titanium.UI.currentWindow;
  3.  
  4. // Include Date.js via CommonJS require()
  5. //require('date-en-GB');
  6. require('date');
  7.  
  8. // declare geo vars
  9. var longitude;
  10. var latitude;
  11. var altitude;
  12. var heading;
  13. var accuracy;
  14. var speed;
  15. var timestamp;
  16. var altitudeAccuracy;
  17.  
  18. //Ti.Geolocation.preferredProvider = "gps";
  19.  
  20. //purpose property for using Location services on iPhone
  21. Ti.Geolocation.purpose = "Get User Location";
  22.  
  23.  
  24.  
  25. if (Titanium.Geolocation.locationServicesEnabled === false)
  26. {
  27. Titanium.UI.createAlertDialog({title:'Gig Finder', message:'Your must turn on location settings to see your nearest comedy shows.'}).show();
  28. }
  29. else
  30. {
  31.  
  32. Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
  33.  
  34. //
  35. // SET DISTANCE FILTER. THIS DICTATES HOW OFTEN AN EVENT FIRES BASED ON THE DISTANCE THE DEVICE MOVES
  36. // THIS VALUE IS IN METERS
  37. //
  38. Titanium.Geolocation.distanceFilter = 10;
  39.  
  40. //
  41. // GET CURRENT POSITION - THIS FIRES ONCE
  42. //
  43. Titanium.Geolocation.getCurrentPosition(function(e)
  44. {
  45. if (!e.success || e.error)
  46. {
  47. currentLocation.text = 'error: ' + JSON.stringify(e.error);
  48. Ti.API.info("Code translation: "+translateErrorCode(e.code));
  49. alert('error ' + JSON.stringify(e.error));
  50. return;
  51. }
  52.  
  53. var longitude = e.coords.longitude;
  54. var latitude = e.coords.latitude;
  55. var altitude = e.coords.altitude;
  56. var heading = e.coords.heading;
  57. var accuracy = e.coords.accuracy;
  58. var speed = e.coords.speed;
  59. var timestamp = e.coords.timestamp;
  60. var altitudeAccuracy = e.coords.altitudeAccuracy;
  61.  
  62. });
  63.  
  64. function loadGigs() {
  65. // Empty array "rowData" for our tableview
  66. var rowData = [];
  67. // Create our HTTP Client and name it "loader"
  68. var loader = Titanium.Network.createHTTPClient();
  69. // Sets the HTTP request method, and the URL to get data from
  70. loader.open("GET", "http://www.mywebsite.com/json.php?lat=" + latitude + "&lng=" + longitude + "&radius=25");
  71. // Runs the function when the data is ready for us to process
  72. loader.onload = function () {
  73. var gigs = eval('(' + this.responseText + ')');
  74. for (var i = 0; i < gigs.length; i++) {
  75. var show_time = gigs[i].show_time; // Show Time
  76. var show_date = gigs[i].show_date; // Show Date
  77. var venue_name = gigs[i].venue_name; // Show Venue
  78. var show_price = gigs[i].price; // Show Price
  79. var show_name = gigs[i].show_name; // Show Name
  80. var comic_name = gigs[i].comic_name; // Names of Comics
  81. var distance = gigs[i].distance; // Distance
  82. var distance_rounded = Math.round(distance * 10) / 10; // rounded Distance
  83.  
  84. // Date clean up, looking good!
  85. var date = Date.parse(show_date);
  86. var datecleaned = date.toString('dddd, MMMM dd yyyy');
  87.  
  88. // Time clean up
  89. var time = Date.parse(show_time);
  90. var timecleaned = time.toString('h:mm tt');
  91.  
  92.  
  93. // Create a row and set its height to auto
  94. var row = Titanium.UI.createTableViewRow({
  95. hasDetail: true,
  96. height: 100
  97. });
  98.  
  99. // if the entry has no data for show name, then show the comic name instead
  100. if (show_name == '') {
  101.  
  102. var show_lbl = Titanium.UI.createLabel({
  103. text: comic_name,
  104. left: 10,
  105. top: 10,
  106. height: 25,
  107. width: 260,
  108. textAlign: 'left',
  109. font: {
  110. fontSize: 18,
  111. fontWeight: 'bold'
  112. }
  113. });
  114.  
  115. } else {
  116.  
  117. var show_lbl = Titanium.UI.createLabel({
  118. text: show_name,
  119. left: 10,
  120. top: 10,
  121. height: 25,
  122. width: 260,
  123. textAlign: 'left',
  124. font: {
  125. fontSize: 18,
  126. fontWeight: 'bold'
  127. }
  128. });
  129. }
  130.  
  131.  
  132. row.add(show_lbl);
  133. // Create the label to hold the screen name
  134. var venue_lbl = Titanium.UI.createLabel({
  135. text: venue_name,
  136. left: 10,
  137. height: 'auto',
  138. top: 32,
  139. width: 260,
  140. textAlign: 'left',
  141. color: '#444444',
  142. font: {
  143. fontSize: 14,
  144. fontWeight: 'bold'
  145. }
  146. });
  147. row.add(venue_lbl);
  148. // Create the label to hold the tweet message
  149. var showdate_lbl = Titanium.UI.createLabel({
  150. text: datecleaned + " " + timecleaned,
  151. left: 10,
  152. height: 15,
  153. top: 52,
  154. width: 260,
  155. textAlign: 'left',
  156. font: {
  157. fontSize: 14
  158. }
  159. });
  160. row.add(showdate_lbl);
  161.  
  162.  
  163. if (show_price > '') {
  164. // Create the label to hold the tweet message
  165. var showprice_lbl = Titanium.UI.createLabel({
  166. text: "Price: " + show_price,
  167. left: 10,
  168. top: 75,
  169. height: 'auto',
  170. width: 260,
  171. textAlign: 'left',
  172. font: {
  173. fontSize: 16,
  174. fontWeight: 'bold'
  175. }
  176. });
  177. row.add(showprice_lbl);
  178. }
  179. // Create the label to hold the tweet message
  180. var distance_lbl = Titanium.UI.createLabel({
  181. text: distance_rounded + ' miles',
  182. left: 10,
  183. top: 120,
  184. height: 'auto',
  185. width: 260,
  186. textAlign: 'left',
  187. font: {
  188. fontSize: 14
  189. }
  190. });
  191. //row.add(distance_lbl);
  192.  
  193.  
  194. // Add the post view to the row
  195. //row.add(post_view);
  196. // Give each row a class name
  197. row.className = "item" + i;
  198. // Add row to the rowData array
  199. rowData[i] = row;
  200. }
  201. // Create the table view and set its data source to "rowData" array
  202. var tableView = Titanium.UI.createTableView({
  203. data: rowData
  204. });
  205. //Add the table view to the window
  206. win.add(tableView);
  207.  
  208. tableView.addEventListener('click', function (e) {
  209. var detailWindow = Ti.UI.createWindow({
  210. barColor: '#000000',
  211. titleImage: 'images/news_header.png'
  212. });
  213.  
  214. var detailView = Ti.UI.createWebView({
  215. html: "<p>Details</p>"
  216. });
  217.  
  218.  
  219. detailWindow.add(detailView);
  220.  
  221. // add the close button
  222. var closeButton = Titanium.UI.createButton({
  223. title: 'Close',
  224. style: Titanium.UI.iPhone.SystemButtonStyle.PLAIN
  225. });
  226. detailWindow.setLeftNavButton(closeButton);
  227. closeButton.addEventListener('click', function () {
  228. detailWindow.close();
  229. });
  230. detailWindow.open({
  231. modal: true,
  232. modalTransitionStyle:Ti.UI.iPhone.MODAL_TRANSITION_STYLE_FLIP_HORIZONTAL
  233. });
  234. });
  235. };
  236. // Send the HTTP request
  237. loader.send();
  238. }
  239. loadGigs();
  240.  
  241. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement