<!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){ //console.log(position.coords.latitude); //console.log(position.coords.longitude); var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); var geocoder = new google.maps.Geocoder(); geocoder.geocode({'latLng': latlng}, function(results, status) { $("#result").html(""); if (status == google.maps.GeocoderStatus.OK) { if(results){ for(var i = 0; i < results.length; i++){ $("#result").append(results[i].formatted_address + "<br>") } } else{ console.log("結果が見つかりませんでした"); } } else{ console.log("ステータス:" + status); } }); }, //位置情報の取得に失敗した時の処理 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>