设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 数据 手机
当前位置: 首页 > 站长学院 > MySql教程 > 正文

突袭HTML5之Javascript API扩展2—地理信息服务及地理位置API学习(3)

发布时间:2020-11-27 15:02 所属栏目:115 来源:网络整理
导读:!DOCTYPE html html head titleGeolocation API Example: Listening for Location Updates/title meta http-equiv="X-UA-Compatible" content="IE=9" / script type="text/javascript" function setText(val, e) {


<!DOCTYPE html>
<html>
<head>
<title>Geolocation API Example: Listening for Location Updates</title>
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<script type="text/javascript">
function setText(val, e) {
document.getElementById(e).value = val;
}
var nav = null;
var watchID;
function listenForPositionUpdates() {
if (nav == null) {
nav = window.navigator;
}
if (nav != null) {
var geoloc = nav.geolocation;
if (geoloc != null) {
watchID = geoloc.watchPosition(successCallback);
}
else {
alert("geolocation not supported");
}
}
else {
alert("Navigator not found");
}
}
function clearWatch(watchID) {
window.navigator.geolocation.clearWatch(watchID);
}
function successCallback(position)
{
setText(position.coords.latitude, "latitude");
setText(position.coords.longitude, "longitude");
}
</script>
</head>
<body>
<label for="latitude">Latitude: </label><input />

<label for="longitude">Longitude: </label><input />

<input type="button" value="Watch Latitude and Longitude" />
<input type="button" value="Clear watch" />
</body>
</html>


实用参考:
官方文档:
脚本之家:https://www.jb51.net/w3school/html5/
微软帮助:(v=vs.85)
百度地图API:

(编辑:ASP站长网)

网友评论
推荐文章
    热点阅读