<!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.watchPosition( //位置情報の取得に成功した時の処理 function(position){ //Google Mapを表示 var lat = position.coords.latitude; var lon = position.coords.longitude; var mapCenter = new google.maps.LatLng(lat,lon); var mapdiv = document.getElementById("gmap"); var myOptions = { zoom:16, center:mapCenter, mapTypeId:google.maps.MapTypeId.ROADMAP, scaleControl:true }; var map = new google.maps.Map(mapdiv,myOptions); var marker = new google.maps.Marker({ position:mapCenter, map:map, title:"現在地" }); map.setCenter(mapCenter); }, //位置情報の取得に失敗した時の処理 function(){ $("#gmap").html("エラーが発生しました"); }, //オプション { enableHighAccuracy:true, timeout:1000 } ); }); </script> <style> #gmap{ height: 500px; background: #eee; border: 1px solid #e1deda; } </style> </head> <body> <div data-role="page" id="index"> <div data-role="header"> <h1>連続して位置情報を取得する</h1> </div> <div data-role="content"> <div id="gmap"></div> </div> <div data-role="footer" data-position="fixed"> <h4>Yohsuke Nakano</h4> </div> </div> </body> </html>