Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Create variable "win" to refer to current window
- var win = Titanium.UI.currentWindow;
- // Include Date.js via CommonJS require()
- //require('date-en-GB');
- require('date');
- // declare geo vars
- var longitude;
- var latitude;
- var altitude;
- var heading;
- var accuracy;
- var speed;
- var timestamp;
- var altitudeAccuracy;
- //Ti.Geolocation.preferredProvider = "gps";
- //purpose property for using Location services on iPhone
- Ti.Geolocation.purpose = "Get User Location";
- if (Titanium.Geolocation.locationServicesEnabled === false)
- {
- Titanium.UI.createAlertDialog({title:'Gig Finder', message:'Your must turn on location settings to see your nearest comedy shows.'}).show();
- }
- else
- {
- Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
- //
- // SET DISTANCE FILTER. THIS DICTATES HOW OFTEN AN EVENT FIRES BASED ON THE DISTANCE THE DEVICE MOVES
- // THIS VALUE IS IN METERS
- //
- Titanium.Geolocation.distanceFilter = 10;
- //
- // GET CURRENT POSITION - THIS FIRES ONCE
- //
- Titanium.Geolocation.getCurrentPosition(function(e)
- {
- if (!e.success || e.error)
- {
- currentLocation.text = 'error: ' + JSON.stringify(e.error);
- Ti.API.info("Code translation: "+translateErrorCode(e.code));
- alert('error ' + JSON.stringify(e.error));
- return;
- }
- var longitude = e.coords.longitude;
- var latitude = e.coords.latitude;
- var altitude = e.coords.altitude;
- var heading = e.coords.heading;
- var accuracy = e.coords.accuracy;
- var speed = e.coords.speed;
- var timestamp = e.coords.timestamp;
- var altitudeAccuracy = e.coords.altitudeAccuracy;
- });
- function loadGigs() {
- // Empty array "rowData" for our tableview
- var rowData = [];
- // Create our HTTP Client and name it "loader"
- var loader = Titanium.Network.createHTTPClient();
- // Sets the HTTP request method, and the URL to get data from
- loader.open("GET", "http://www.mywebsite.com/json.php?lat=" + latitude + "&lng=" + longitude + "&radius=25");
- // Runs the function when the data is ready for us to process
- loader.onload = function () {
- var gigs = eval('(' + this.responseText + ')');
- for (var i = 0; i < gigs.length; i++) {
- var show_time = gigs[i].show_time; // Show Time
- var show_date = gigs[i].show_date; // Show Date
- var venue_name = gigs[i].venue_name; // Show Venue
- var show_price = gigs[i].price; // Show Price
- var show_name = gigs[i].show_name; // Show Name
- var comic_name = gigs[i].comic_name; // Names of Comics
- var distance = gigs[i].distance; // Distance
- var distance_rounded = Math.round(distance * 10) / 10; // rounded Distance
- // Date clean up, looking good!
- var date = Date.parse(show_date);
- var datecleaned = date.toString('dddd, MMMM dd yyyy');
- // Time clean up
- var time = Date.parse(show_time);
- var timecleaned = time.toString('h:mm tt');
- // Create a row and set its height to auto
- var row = Titanium.UI.createTableViewRow({
- hasDetail: true,
- height: 100
- });
- // if the entry has no data for show name, then show the comic name instead
- if (show_name == '') {
- var show_lbl = Titanium.UI.createLabel({
- text: comic_name,
- left: 10,
- top: 10,
- height: 25,
- width: 260,
- textAlign: 'left',
- font: {
- fontSize: 18,
- fontWeight: 'bold'
- }
- });
- } else {
- var show_lbl = Titanium.UI.createLabel({
- text: show_name,
- left: 10,
- top: 10,
- height: 25,
- width: 260,
- textAlign: 'left',
- font: {
- fontSize: 18,
- fontWeight: 'bold'
- }
- });
- }
- row.add(show_lbl);
- // Create the label to hold the screen name
- var venue_lbl = Titanium.UI.createLabel({
- text: venue_name,
- left: 10,
- height: 'auto',
- top: 32,
- width: 260,
- textAlign: 'left',
- color: '#444444',
- font: {
- fontSize: 14,
- fontWeight: 'bold'
- }
- });
- row.add(venue_lbl);
- // Create the label to hold the tweet message
- var showdate_lbl = Titanium.UI.createLabel({
- text: datecleaned + " " + timecleaned,
- left: 10,
- height: 15,
- top: 52,
- width: 260,
- textAlign: 'left',
- font: {
- fontSize: 14
- }
- });
- row.add(showdate_lbl);
- if (show_price > '') {
- // Create the label to hold the tweet message
- var showprice_lbl = Titanium.UI.createLabel({
- text: "Price: " + show_price,
- left: 10,
- top: 75,
- height: 'auto',
- width: 260,
- textAlign: 'left',
- font: {
- fontSize: 16,
- fontWeight: 'bold'
- }
- });
- row.add(showprice_lbl);
- }
- // Create the label to hold the tweet message
- var distance_lbl = Titanium.UI.createLabel({
- text: distance_rounded + ' miles',
- left: 10,
- top: 120,
- height: 'auto',
- width: 260,
- textAlign: 'left',
- font: {
- fontSize: 14
- }
- });
- //row.add(distance_lbl);
- // Add the post view to the row
- //row.add(post_view);
- // Give each row a class name
- row.className = "item" + i;
- // Add row to the rowData array
- rowData[i] = row;
- }
- // Create the table view and set its data source to "rowData" array
- var tableView = Titanium.UI.createTableView({
- data: rowData
- });
- //Add the table view to the window
- win.add(tableView);
- tableView.addEventListener('click', function (e) {
- var detailWindow = Ti.UI.createWindow({
- barColor: '#000000',
- titleImage: 'images/news_header.png'
- });
- var detailView = Ti.UI.createWebView({
- html: "<p>Details</p>"
- });
- detailWindow.add(detailView);
- // add the close button
- var closeButton = Titanium.UI.createButton({
- title: 'Close',
- style: Titanium.UI.iPhone.SystemButtonStyle.PLAIN
- });
- detailWindow.setLeftNavButton(closeButton);
- closeButton.addEventListener('click', function () {
- detailWindow.close();
- });
- detailWindow.open({
- modal: true,
- modalTransitionStyle:Ti.UI.iPhone.MODAL_TRANSITION_STYLE_FLIP_HORIZONTAL
- });
- });
- };
- // Send the HTTP request
- loader.send();
- }
- loadGigs();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement