Advertisement
Guest User

Untitled

a guest
May 20th, 2019
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. <template>
  2. <Page class="page">
  3. <ActionBar title="Geolocation" class="action-bar" />
  4. <StackLayout class="home-panel">
  5.  
  6. <Button text="Get My Item" @tap="getItem" class="btn btn-primary" />
  7.  
  8. <StackLayout>
  9. <Button text="Show location" @tap="enableLocationServices"
  10. :visibility="currentGeoLocation.latitude ? 'collapsed' : 'visible'"
  11. class="btn btn-primary" />
  12. <StackLayout :visibility="currentGeoLocation.latitude ? 'visible' : 'collapsed'">
  13. <Label :text="'Latitude: ' + currentGeoLocation.latitude" />
  14. <Label :text="'Longitude: ' + currentGeoLocation.longitude" />
  15. <Label :text="'Altitude: ' + currentGeoLocation.altitude" />
  16. <Label :text="'Direction: ' + currentGeoLocation.direction" />
  17. </StackLayout>
  18. </StackLayout>
  19.  
  20. <Label :text="'Items: ' + collectedItems" class="lbl" :key="collectedItems" />
  21. </StackLayout>
  22. </Page>
  23. </template>
  24.  
  25. <script>
  26. const geoLocation = require("nativescript-geolocation");
  27.  
  28. const app = require("tns-core-modules/application");
  29. const platform = require("tns-core-modules/platform");
  30. const Vue = require("nativescript-vue");
  31. const httpModule = require("http");
  32. const geolocation = require("nativescript-geolocation");
  33. const {
  34. Accuracy
  35. } = require("tns-core-modules/ui/enums");
  36. export default {
  37. data() {
  38. return {
  39. currentGeoLocation: {
  40. latitude: null,
  41. longitude: null,
  42. altitude: null,
  43. direction: null
  44. },
  45.  
  46. accelerometerValues: {
  47. x: null,
  48. y: null,
  49. z: null
  50. },
  51.  
  52. lat: "",
  53. lon: "",
  54. speed: "",
  55. addr: "",
  56. selectedItems: "",
  57. collectedItems: [null]
  58. };
  59. },
  60. methods: {
  61. enableLocationServices: function() {
  62. geoLocation.isEnabled().then(enabled => {
  63. if (!enabled) {
  64. geoLocation
  65. .enableLocationRequest()
  66. .then(() => this.showLocation());
  67. } else {
  68. this.showLocation();
  69. }
  70. });
  71. },
  72. showLocation: function() {
  73. geoLocation.watchLocation(
  74. location => {
  75. this.currentGeoLocation = location;
  76. },
  77. error => {
  78. alert(error);
  79. }, {
  80. desiredAccuracy: 3,
  81. updateDistance: 10,
  82. minimumUpdateTime: 1000 * 1
  83. }
  84. );
  85. },
  86.  
  87. getItem() {
  88. httpModule
  89. .getJSON(
  90. "https://fortnite-public-api.theapinetwork.com/prod09/items/list"
  91. )
  92. .then(
  93. result => {
  94. // var i;
  95. var random = Math.floor(
  96. Math.random() * (+result.length - 0)
  97. );
  98. // for (i = 0; i < result.length; i++){
  99. this.collectedItems.push(
  100. JSON.stringify(result[random].name)
  101. );
  102. this.collectedItems.toString();
  103. console.log(this.collectedItems);
  104. },
  105. function(error) {
  106. console.error(JSON.stringify(error));
  107. }
  108. );
  109. }
  110. }
  111. };
  112. </script>
  113. <style scoped>
  114. .home-panel {
  115. vertical-align: center;
  116. font-size: 20;
  117. margin: 15;
  118. }
  119.  
  120. .description-label {
  121. margin-bottom: 15;
  122. }
  123. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement