欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

怎么在html5中使用Geolocation實現(xiàn)一個定位功能-創(chuàng)新互聯(lián)

今天就跟大家聊聊有關怎么在html5中使用Geolocation實現(xiàn)一個定位功能,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

在東烏珠穆沁等地區(qū),都構建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務理念,為客戶提供網(wǎng)站設計、成都網(wǎng)站制作 網(wǎng)站設計制作按需設計網(wǎng)站,公司網(wǎng)站建設,企業(yè)網(wǎng)站建設,成都品牌網(wǎng)站建設,網(wǎng)絡營銷推廣,成都外貿(mào)網(wǎng)站制作,東烏珠穆沁網(wǎng)站建設費用合理。


1.獲取當前位置
我們將使用getCurrentPosition方法獲取當前位置,位置信息不會以結果的形式直接返回,我們需要使用callback函數(shù)進行處理。在獲取坐標的過程中會有些延遲,還會問你要訪問權限。我們來看下面的例子:



代碼如下:

<!DOCTYPE HTML> 
<html> 
<head> 
<title>Example</title> 
<style> 
table{border-collapse: collapse;} 
th, td{padding: 4px;} 
th{text-align: right;} 
</style> 
</head> 
<body> 
<table border="1"> 
<tr> 
<th>Longitude:</th> 
<td id="longitude">-</td> 
<th>Latitude:</th> 
<td id="latitude">-</td> 
</tr> 
<tr> 
<th>Altitude:</th> 
<td id="altitude">-</td> 
<th>Accuracy:</th> 
<td id="accuracy">-</td> 
</tr> 
<tr> 
<th>Altitude Accuracy:</th> 
<td id="altitudeAccuracy">-</td> 
<th>Heading:</th> 
<td id="heading">-</td> 
</tr> 
<tr> 
<th>Speed:</th> 
<td id="speed">-</td> 
<th>Time Stamp:</th> 
<td id="timestamp">-</td> 
</tr> 
</table> 
<script> 
navigator.geolocation.getCurrentPosition(displayPosition); 
function displayPosition(pos) { 
var properties = ['longitude', 'latitude', 'altitude', 'accuracy', 'altitudeAccuracy', 'heading', 'speed']; 
for (var i = 0, len = properties.length; i < len; i++) { 
var value = pos.coords[properties[i]]; 
document.getElementById(properties[i]).innerHTML = value; 
} 
document.getElementById('timestamp').innerHTML = pos.timestamp; 
} 
</script> 
</body> 
</html>


返回的position對象包含兩個屬性,coords:返回坐標信息;timestamp:獲取坐標信息的時間。其中coords又包括下面屬性:latitude:緯度;longitude:經(jīng)度;altitude:高度;accuracy:精確度(米);altitudeAccuracy:高度精確度(米);heading:行進方向;speed:行進速度(米/秒)。
并不是所有的信息都會返回,這取決于你承載瀏覽器的設備。像有GPS、加速器、羅盤的移動設備會返回大部分信息,家用電腦就不行了。家用電腦獲取的位置信息,取決于所處的網(wǎng)絡環(huán)境或者是wifi。下面我們看上例的運行結果。


怎么在html5中使用Geolocation實現(xiàn)一個定位功能


點擊允許,獲取坐標信息。


怎么在html5中使用Geolocation實現(xiàn)一個定位功能

2.處理異常
現(xiàn)在我們介紹getCurrentPosition的異常處理,他是通過使用errorCallback回調(diào)函數(shù)實現(xiàn)的。函數(shù)返回的參數(shù)error包含兩個屬性,code:錯誤類型的代碼;message:錯誤信息。code包含三個值:1:用戶沒有授權使用geolocation;2:無法獲取坐標信息;3:獲取信息超時。
下面我們看個例子:



代碼如下:


<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
<style>
table{border-collapse: collapse;}
th, td{padding: 4px;}
th{text-align: right;}
</style>
</head>
<body>
<table border="1">
<tr>
<th>Longitude:</th>
<td id="longitude">-</td>
<th>Latitude:</th>
<td id="latitude">-</td>
</tr>
<tr>
<th>Altitude:</th>
<td id="altitude">-</td>
<th>Accuracy:</th>
<td id="accuracy">-</td>
</tr>
<tr>
<th>Altitude Accuracy:</th>
<td id="altitudeAccuracy">-</td>
<th>Heading:</th>
<td id="heading">-</td>
</tr>
<tr>
<th>Speed:</th>
<td id="speed">-</td>
<th>Time Stamp:</th>
<td id="timestamp">-</td>
</tr>
<tr>
<th>Error Code:</th>
<td id="errcode">-</td>
<th>Error Message:</th>
<td id="errmessage">-</td>
</tr>
</table>
<script>
navigator.geolocation.getCurrentPosition(displayPosition, handleError);
function displayPosition(pos) {
var properties = ["longitude", "latitude", "altitude", "accuracy", "altitudeAccuracy", "heading", "speed"];
for (var i = 0; i < properties.length; i++) {
var value = pos.coords[properties[i]];
document.getElementById(properties[i]).innerHTML = value;
}
document.getElementById("timestamp").innerHTML = pos.timestamp;
}
function handleError(err) {
document.getElementById("errcode").innerHTML = err.code;
document.getElementById("errmessage").innerHTML = err.message;
}
</script>
</body>
</html>



拒絕授權,運行結果:


怎么在html5中使用Geolocation實現(xiàn)一個定位功能

3.使用geolocation可選參數(shù)項
getCurrentPosition(callback,errorCallback,options)中的options有如下參數(shù)可以使用,enableHighAccuracy:使用好的效果;timeout:超時時間(毫秒);maximumAge:指定緩存時間(毫秒)。我們來下下面的例子:



代碼如下:


<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
<style>
table{border-collapse: collapse;}
th, td{padding: 4px;}
th{text-align: right;}
</style>
</head>
<body>
<table border="1">
<tr>
<th>Longitude:</th>
<td id="longitude">-</td>
<th>Latitude:</th>
<td id="latitude">-</td>
</tr>
<tr>
<th>Altitude:</th>
<td id="altitude">-</td>
<th>Accuracy:</th>
<td id="accuracy">-</td>
</tr>
<tr>
<th>Altitude Accuracy:</th>
<td id="altitudeAccuracy">-</td>
<th>Heading:</th>
<td id="heading">-</td>
</tr>
<tr>
<th>Speed:</th>
<td id="speed">-</td>
<th>Time Stamp:</th>
<td id="timestamp">-</td>
</tr>
<tr>
<th>Error Code:</th>
<td id="errcode">-</td>
<th>Error Message:</th>
<td id="errmessage">-</td>
</tr>
</table>
<script>
var options = {
enableHighAccuracy: false,
timeout: 2000,
maximumAge: 30000
};
navigator.geolocation.getCurrentPosition(displayPosition, handleError, options);
function displayPosition(pos) {
var properties = ["longitude", "latitude", "altitude", "accuracy", "altitudeAccuracy", "heading", "speed"];
for (var i = 0; i < properties.length; i++) {
var value = pos.coords[properties[i]];
document.getElementById(properties[i]).innerHTML = value;
}
document.getElementById("timestamp").innerHTML = pos.timestamp;
}
function handleError(err) {
document.getElementById("errcode").innerHTML = err.code;
document.getElementById("errmessage").innerHTML = err.message;
}
</script>
</body>
</html>



4.監(jiān)視位置變化
下面我們介紹使用watchPosition方法實現(xiàn)位置變化的監(jiān)視,他的使用方法和getCurrentPosition一樣。我們來看例子:



代碼如下:


<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
<style>
table{border-collapse: collapse;}
th, td{padding: 4px;}
th{text-align: right;}
</style>
</head>
<body>
<table border="1">
<tr>
<th>Longitude:</th>
<td id="longitude">-</td>
<th>Latitude:</th>
<td id="latitude">-</td>
</tr>
<tr>
<th>Altitude:</th>
<td id="altitude">-</td>
<th>Accuracy:</th>
<td id="accuracy">-</td>
</tr>
<tr>
<th>Altitude Accuracy:</th>
<td id="altitudeAccuracy">-</td>
<th>Heading:</th>
<td id="heading">-</td>
</tr>
<tr>
<th>Speed:</th>
<td id="speed">-</td>
<th>Time Stamp:</th>
<td id="timestamp">-</td>
</tr>
<tr>
<th>Error Code:</th>
<td id="errcode">-</td>
<th>Error Message:</th>
<td id="errmessage">-</td>
</tr>
</table>
<button id="pressme">Cancel Watch</button>
<script>
var options = {
enableHighAccuracy: false,
timeout: 2000,
maximumAge: 30000
};
var watchID = navigator.geolocation.watchPosition(displayPosition, handleError, options);
document.getElementById("pressme").onclick = function (e) {
navigator.geolocation.clearWatch(watchID);
};
function displayPosition(pos) {
var properties = ["longitude", "latitude", "altitude", "accuracy", "altitudeAccuracy", "heading", "speed"];
for (var i = 0; i < properties.length; i++) {
var value = pos.coords[properties[i]];
document.getElementById(properties[i]).innerHTML = value;
}
document.getElementById("timestamp").innerHTML = pos.timestamp;
}
function handleError(err) {
document.getElementById("errcode").innerHTML = err.code;
document.getElementById("errmessage").innerHTML = err.message;
}
</script>
</body>
</html>


看完上述內(nèi)容,你們對怎么在html5中使用Geolocation實現(xiàn)一個定位功能有進一步的了解嗎?如果還想了解更多知識或者相關內(nèi)容,請關注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。

網(wǎng)站欄目:怎么在html5中使用Geolocation實現(xiàn)一個定位功能-創(chuàng)新互聯(lián)
URL鏈接:http://aaarwkj.com/article2/jcoic.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護、Google品牌網(wǎng)站建設、網(wǎng)站制作定制網(wǎng)站、定制開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作
免费在线观看做性小视频| 日韩女同性一区二区三区| 日本一道本不卡一区二区| 欧美精品一区二区精品久久| 九九视频精品免费高清视频| 成人福利在线观看免费视频| 色综合久久国产原创野外| 国产三级视频在线2022| 女人的天堂av免费在线观看| 欧美国产精品久久综合| 最新日韩欧美一区二区| 久久婷婷综合激情亚洲| 国产黄色片网站在线看| 国产精品亚洲av性色| 尤物视频官网在线观看| 国产口爆一区二区三区| 麻豆国产精品原创av男女| 丰满人妻毛片一区二区三区| 国产精品成人av在线| 首页亚洲一区二区三区| 亚洲一区二区三区日韩精品| 久久精品一区二区三区乱码| 欧美偷拍一区二区三区| 国产三级精品大乳人妇| 18岁以下禁止观看的视频| 欧美人妻不卡一区二区久久| 高清av在线国产成人精品自拍| 国产精品一区二区夜夜夜| 国产精品夫妇在线激情啪| 久久东京热日韩精品一区| avav男人天堂亚洲天堂| 国产一区黄片视频在线观看| 丁香六月色婷婷亚洲激情 | 亚洲欧美日韩在线观看a三区| 日韩精品有码在线视频免费观看| 日本三本道成人免费毛片| 传媒视频在线免费观看| 成人av在线免费播放| av在线亚洲网站区一| 精品久久久久久蜜臀av| 亚洲国产在线一区二区|