HTML5地理定位實(shí)例
發(fā)布時(shí)間:2014-10-15 16:31:41 作者:佚名
我要評(píng)論

這篇文章主要為大家介紹了HTML5地理定位的方法,實(shí)例講述了html5獲取坐標(biāo)完整實(shí)現(xiàn)過(guò)程,并對(duì)比不同瀏覽器運(yùn)行效果給出參考結(jié)果,需要的朋友可以參考下
本文實(shí)例講述了html5獲取地理定位的方法,分享給大家供大家參考。具體方法如下:
html5 獲取坐標(biāo)代碼如下:
復(fù)制代碼
代碼如下:<!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">點(diǎn)擊這個(gè)按鈕,獲得您的坐標(biāo):</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>
<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">點(diǎn)擊這個(gè)按鈕,獲得您的坐標(biāo):</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>
經(jīng)測(cè)試,在IE9 、firefox、chrome、opera上都可以成功獲取到坐標(biāo)位置,但是safari 5.x上卻不能返回坐標(biāo),暫時(shí)木有找到原因。成功的案例里頭,chrome響應(yīng)的速度最快,其次是opera,然后是IE9,firefox居然是最慢的。個(gè)人表示對(duì)firefox很失望,不過(guò)chrome倒是越來(lái)棒了。
希望本文所述對(duì)大家的HTML5程序設(shè)計(jì)有所幫助。
相關(guān)文章
HTML5地理定位_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
地理位置(Geolocation)是 HTML5 的重要特性之一,提供了確定用戶位置的功能,借助這個(gè)特性能夠開(kāi)發(fā)基于位置信息的應(yīng)用。今天這篇文章向大家介紹一下 HTML5 地理位置定位2017-07-12HTML5實(shí)現(xiàn)獲取地理位置信息并定位功能
這篇文章主要介紹了HTML5實(shí)現(xiàn)獲取地理位置信息并定位功能,本文講解了原生HTML5、百度地圖、谷歌地圖等三種獲取理位置信息并定位的方法,需要的朋友可以參考下2015-04-25- 這篇文章主要介紹了使用html5代碼來(lái)獲取地理位置,具體實(shí)現(xiàn)代碼如下并附有截圖,需要的朋友可以參考下2014-03-31
h5實(shí)現(xiàn)獲取用戶地理定位的實(shí)例代碼
本篇文章主要介紹了h5實(shí)現(xiàn)獲取地理定位的實(shí)例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-07-17