Guest User

Untitled

a guest
Jan 19th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. <script>
  2. // 現在地取得処理
  3. function getPosition() {
  4. // Geolocation APIに対応している場合 -> 何もしない
  5. if (navigator.geolocation) {
  6.  
  7. // Geolocation APIに対応していない場合 -> アラート
  8. } else {
  9. alert("この端末では位置情報が取得できません");
  10. }
  11. // 現在地を取得
  12. navigator.geolocation.getCurrentPosition(
  13. // 取得成功した場合 -> 緯度経度を表示
  14. function(position) {
  15. alert("緯度:"+position.coords.latitude+",経度"+position.coords.longitude);
  16. },
  17. // 取得失敗した場合 -> エラー処理
  18. function(error) {
  19. switch(error.code) {
  20. case 1: //PERMISSION_DENIED
  21. alert("位置情報の利用が許可されていません");
  22. break;
  23. case 2: //POSITION_UNAVAILABLE
  24. alert("現在位置が取得できませんでした");
  25. break;
  26. case 3: //TIMEOUT
  27. alert("タイムアウトになりました");
  28. break;
  29. default:
  30. alert("その他のエラー(エラーコード:"+error.code+")");
  31. break;
  32. }
  33. }
  34. );
  35. }
  36. </script>
Add Comment
Please, Sign In to add comment