DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> HTML基礎知識 >> HTML5教程 >> HTML5地理定位實例
HTML5地理定位實例
編輯:HTML5教程     

 html5 獲取坐標代碼如下:

代碼如下: <!DOCTYPE HTML>
<html>
<head>
<title>test1.html</title>

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<div id="demo">點擊這個按鈕,獲得您的坐標:</div>
<button onclick="getLocation()">試一下</button>
<script type="text/javascript">

var x=document.getElementById("demo");
function getLocation(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(showPosition);
}else{
x.innerHTML="浏覽器不支持!!!";
}
}
function showPosition(position){
x.innerHTML="Latitude: "+position.coords.latitude+"<br/>Longitude: "+position.coords.longitude;
}
</script>

</body>
</html>

 

經測試,在IE9 、firefox、chrome、opera上都可以成功獲取到坐標位置,但是safari 5.x上卻不能返回坐標,暫時木有找到原因。成功的案例裡頭,chrome響應的速度最快,其次是opera,然後是IE9,firefox居然是最慢的。個人表示對firefox很失望,不過chrome倒是越來棒了。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved