Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. <template>
  2. <div class="about">
  3. <h1>現在地</h1>
  4. <p>緯度:{{latitude}}</p>
  5. <p>経度:{{longitude}}</p>
  6.  
  7. <h2>歩いた距離</h2>
  8. <p>1分間で歩いた距離:{{d}} km</p>
  9. <p>合計:{{length}} km</p>
  10. </div>
  11. </template>
  12.  
  13. <sciprt>
  14. // 一部
  15. lat1: number;
  16. lng1: number;
  17. lat2: number;
  18. lng2: number;
  19.  
  20. d: number;
  21. length: number;
  22.  
  23. //60秒毎にcalcDistance関数を実行する
  24. setInterval(calcDistance, 60000);
  25.  
  26. calcDistance(){
  27.  
  28. const position = Geolocation.getCurrentPosition();
  29. this.lat2 = position.coords.latitude;
  30. this.lng2 = position.coords.longitude;
  31.  
  32. this.d = distance(lat1, lng1, lat2, lng2)
  33. this.length = this.length + this.d
  34.  
  35. this.lat1 = lat2
  36. this.lng1 = lng2
  37. }
  38.  
  39. function distance(lat1, lng1, lat2, lng2) {
  40. lat1 *= Math.PI / 180;
  41. lng1 *= Math.PI / 180;
  42. lat2 *= Math.PI / 180;
  43. lng2 *= Math.PI / 180;
  44. return 6371 * Math.acos(Math.cos(lat1) * Math.cos(lat2) * Math.cos(lng2 - lng1) + Math.sin(lat1) * Math.sin(lat2));
  45. }
  46. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement