Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. angular.module('home', ['services'])
  2.  
  3. .controller('homeCtrl',
  4. function ($scope, $location, $state, serverAPI, $ionicPopup) {
  5.  
  6. $scope.buttonType = "icon ion-search";
  7. $scope.buttonDisable = false;
  8. $scope.text = 'Search';
  9. var UID = JSON.parse(window.localStorage.getItem('Credentials')).UID;
  10. serverAPI.getUserData(UID, function (data) {
  11. $scope.userName = data.userName;
  12. $scope.points = data.points;
  13. $scope.fotoId = data.fotoId;
  14. console.log(data);
  15. });
  16.  
  17.  
  18.  
  19. $scope.click = function () {
  20. $scope.buttonDisable = true;
  21. $scope.text = 'Searching';
  22. $scope.buttonType = 'icon ion-loading-a';
  23.  
  24.  
  25.  
  26. // //Grap geoLocation
  27. var location = navigator.geolocation.getCurrentPosition(saveGeoData, onError);
  28. //
  29.  
  30. function onError(error) {
  31. alert('code: ' + error.code + 'n' +
  32. 'message: ' + error.message + 'n');
  33. };
  34.  
  35. var saveGeoData = function (geoData) {
  36. console.log("nach geo");
  37. var myPosition = {
  38. 'longitude': geoData.coords.longitude,
  39. 'latitude': geoData.coords.latitude
  40. };
  41. console.log("ss");
  42. console.log(myPosition.latitude);
  43. window.localStorage.setItem('myPosition', JSON.stringify(myPosition));
  44. //If geoloaction is saved successfully => Send geodata to server to receive teammate
  45. sendToServer(myPosition);
  46. }
  47.  
  48.  
  49. //Send current location to Server to receive teammate
  50. var sendToServer = function (myPosition) {
  51. serverAPI.searchPartnerToPlayWith(myPosition.longitude, myPosition.latitude, UID, function (data) {
  52.  
  53. //No other players around you. Server returns -1
  54. if (data == -1) {
  55. $ionicPopup.alert({
  56. title: 'Too bad :(',
  57. template: 'Unfortunateley there are no other players around you. Try it some other time!'
  58. });
  59. } else {
  60. window.localStorage.setItem('teammate', data.username);
  61. window.localStorage.setItem('isEnummeration', data.taskType);
  62. window.localStorage.setItem('task', data.task);
  63. var teammatePosition = {
  64. 'longitude': data.longitude,
  65. 'latitude': data.latitude
  66. };
  67. window.localStorage.setItem('teammatePosition', teammatePosition);
  68. //TODO: data.fotoId => request foto from server
  69. $state.go('tab.play-screen');
  70. }
  71.  
  72.  
  73. })
  74. }
  75. };
  76.  
  77. })
  78.  
  79. var location = navigator.geolocation.getCurrentPosition(saveGeoData, onError);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement