Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- // 現在地取得処理
- function getPosition() {
- // Geolocation APIに対応している場合 -> 何もしない
- if (navigator.geolocation) {
- // Geolocation APIに対応していない場合 -> アラート
- } else {
- alert("この端末では位置情報が取得できません");
- }
- // 現在地を取得
- navigator.geolocation.getCurrentPosition(
- // 取得成功した場合 -> 緯度経度を表示
- function(position) {
- alert("緯度:"+position.coords.latitude+",経度"+position.coords.longitude);
- },
- // 取得失敗した場合 -> エラー処理
- function(error) {
- switch(error.code) {
- case 1: //PERMISSION_DENIED
- alert("位置情報の利用が許可されていません");
- break;
- case 2: //POSITION_UNAVAILABLE
- alert("現在位置が取得できませんでした");
- break;
- case 3: //TIMEOUT
- alert("タイムアウトになりました");
- break;
- default:
- alert("その他のエラー(エラーコード:"+error.code+")");
- break;
- }
- }
- );
- }
- </script>
Add Comment
Please, Sign In to add comment