基本Javascript地理位置脚本(HTML5规范)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基本Javascript地理位置脚本(HTML5规范)相关的知识,希望对你有一定的参考价值。
Simple javascript test of the html 5 geolocation API spec
<!DOCTYPE html> <html> <head> <script> var messageDiv = document.getElementById('message'); function initLocation ( ) { // Try HTML5-spec geolocation: http://dev.w3.org/geo/api/spec-source.html var geolocation = navigator.geolocation; if (geolocation) { // Try Catch try { // getCurrentPosition function as stated in the spec navigator.geolocation.getCurrentPosition( successCallback, errorCallback ); } catch (err) { messageDiv.innerHTML = 'Error'; } } else { messageDiv.innerHTML = 'Your browser is not capable of looking up your location.'; } } function successCallback ( location ) { message.innerHTML="<p>Longitude: " + location.coords.longitude + "</p>"; message.innerHTML+="<p>Latitude: " + location.coords.latitude + "</p>"; message.innerHTML+="<p>Accuracy: " + location.coords.accuracy + "</p>"; } function errorCallback ( ) { messageDiv.innerHTML = 'There was an error looking up your position'; } </script> </head> <body onload="initLocation()"> <div id="message">Looking Up Location</div> </body> </html>
以上是关于基本Javascript地理位置脚本(HTML5规范)的主要内容,如果未能解决你的问题,请参考以下文章
自己写的HTML5 Canvas + Javascript五子棋
自己的写的HTML5 Canvas + Javascript五子棋
使用 Tampermonkey/javascript 控制 Netflix (HTML5) 播放