[PR]
×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(success, error); } else { alert('Browser not supported!!!'); } function success(position){ console.log(position); } function error(err){ console.log(err); }
<!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Test Geolocation</title> <meta content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport"/> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script> <script type="text/javascript"> $(function(){ var naviLocation; var startTime; var monitor = $('#monitor'); function currPositionSuccess(position){ console.log(position); } function watchPositionSuccess(position){ console.log(position); var show = $('<div />'); var lat = position.coords.latitude; var lon = position.coords.longitude; var acc = position.coords.accuracy; var currentTime = new Date(); var watchTime = currentTime - startTime; show.text('lat:'+lat+', lon:'+lon+', acc:'+acc+', watchTime:'+watchTime); monitor.append(show); //accuracyが50以下、または監視時間が10秒超えたらやめる if (acc < 50 || watchTime > 10000) { getClearWatch(); } } function error(err){ console.log(err); console.log('error:' + err.message); } //現在位置の取得 function getCurrPosition(){ console.log('getCurrentPosition'); naviLocation = navigator.geolocation.getCurrentPosition(currPositionSuccess, error); } //現在位置の監視 function getWatchPosition(){ console.log('watchPosition'); startTime = new Date(); naviLocation = navigator.geolocation.watchPosition(watchPositionSuccess, error); } //位置監視を終了 function getClearWatch(){ console.log('clearWatch'); navigator.geolocation.clearWatch(naviLocation); } $('#current-position').click(function(){ getCurrPosition(); }); $('#watch-position').click(function(){ getWatchPosition(); }); $('#clear-watch').click(function(){ getClearWatch(); }); }); </script> </head> <body> <button id="current-position"> getCurrentPosition </button> <button id="watch-position"> watchPosition </button> <button id="clear-watch"> clearWatch </button> <br /> <div id="monitor"> </div> </body> </html>
if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(success, error); } else { alert('Browser not supported!!!'); } function success(position){ console.log(position); } function error(err){ console.log(err); }
<!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Test Geolocation</title> <meta content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport"/> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script> <script type="text/javascript"> $(function(){ var naviLocation; var startTime; var monitor = $('#monitor'); function currPositionSuccess(position){ console.log(position); } function watchPositionSuccess(position){ console.log(position); var show = $('<div />'); var lat = position.coords.latitude; var lon = position.coords.longitude; var acc = position.coords.accuracy; var currentTime = new Date(); var watchTime = currentTime - startTime; show.text('lat:'+lat+', lon:'+lon+', acc:'+acc+', watchTime:'+watchTime); monitor.append(show); //accuracyが50以下、または監視時間が10秒超えたらやめる if (acc < 50 || watchTime > 10000) { getClearWatch(); } } function error(err){ console.log(err); console.log('error:' + err.message); } //現在位置の取得 function getCurrPosition(){ console.log('getCurrentPosition'); naviLocation = navigator.geolocation.getCurrentPosition(currPositionSuccess, error); } //現在位置の監視 function getWatchPosition(){ console.log('watchPosition'); startTime = new Date(); naviLocation = navigator.geolocation.watchPosition(watchPositionSuccess, error); } //位置監視を終了 function getClearWatch(){ console.log('clearWatch'); navigator.geolocation.clearWatch(naviLocation); } $('#current-position').click(function(){ getCurrPosition(); }); $('#watch-position').click(function(){ getWatchPosition(); }); $('#clear-watch').click(function(){ getClearWatch(); }); }); </script> </head> <body> <button id="current-position"> getCurrentPosition </button> <button id="watch-position"> watchPosition </button> <button id="clear-watch"> clearWatch </button> <br /> <div id="monitor"> </div> </body> </html>