<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"> <title></title> <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> <script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css"> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script> <script type="text/javascript"> $("#index").live("pageshow",function(){ navigator.geolocation.getCurrentPosition( //位置情報の取得に成功した時の処理 function(position){ var location = "緯度:" + position.coords.latitude + "<br>" + "経度:" + position.coords.longitude + "<br>" + "高度:" + position.coords.altitude + "<br>" + "緯度、経度の誤差:" + position.coords.accuracy + "<br>" + "高度の誤差:" + position.coords.altitudeAccuracy + "<br>" + "方角:" + position.coords.heading + "<br>" + "速度:" + position.coords.speed; $("#result").html(location); }, //位置情報の取得に失敗した時の処理 function(error){ var message = ""; switch(error.code){ case error.TIMEOUT: message = "タイムアウトが発生しました"; break; case error.POSITION_UNAVAILABLE: message = "位置情報が利用できませんでした"; break; case error.PERMISSION_DENIED: message = "Geolocation APIの利用権限がありません"; break; case error.UNKNOWN_ERROR: message = "UNKNOWN_ERROR:" + error.message; break; } $("#result").html(message); }, //オプション { enableHighAccuracy:true, timeout:1000 } ); }); </script> </head> <body> <div data-role="page" id="index"> <div data-role="header"> <h1>位置取得時のエラーを検出する</h1> </div> <div data-role="content"> <div id="result"></div> </div> <div data-role="footer" data-position="fixed"> <h4>Yohsuke Nakano</h4> </div> </div> </body> </html>