Html5 geographical positioning
HTML5 Geolocation
HTML5 Geolocation is used to locate the user's location.
Positioning the position of the user
## HTML5 Geolocation API is used to obtain the user's geographical location.
Given that this feature may violate user privacy, user location information is not available unless the user agrees.
# browser supports
Qi test whether the browser supports:
if (navigator.geolocation) {
//console.log("浏览器支持!");
}else {
// console.log("浏览器不支持!");
} Navigator.Geolocation is used to obtain the current user geographical location of the browser -based, provided 3 Method: RrreerReee Handling errors and rejection of
# stertcurrentposition () method for handling errors. It specifies the function to be run when obtaining the user's location fails: Instancevoid getCurrentPosition(onSuccess,onError,options);//获取用户当前位置 int watchCurrentPosition(onSuccess,onError,options);//持续获取当前用户位置 void clearWatch(watchId);//watchId 为watchCurrentPosition返回的值//取消监控
###
new file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文网(php.cn)</title>
</head>
<body>
<p id="demo">点击按钮获取您当前坐标(可能需要比较长的时间获取):</p>
<button onclick="getLocation()">点我</button>
<script>
var x=document.getElementById("demo");
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition,showError);
}
else{x.innerHTML="Geolocation is not supported by this browser.";}
}
function showPosition(position)
{
x.innerHTML="纬度: " + position.coords.latitude +
"<br>经度: " + position.coords.longitude;
}
function showError(error)
{
switch(error.code)
{
case error.PERMISSION_DENIED:
x.innerHTML="用户拒绝对获取地理位置的请求。"
break;
case error.POSITION_UNAVAILABLE:
x.innerHTML="位置信息是不可用的。"
break;
case error.TIMEOUT:
x.innerHTML="请求用户地理位置超时。"
break;
case error.UNKNOWN_ERROR:
x.innerHTML="未知错误。"
break;
}
}
</script>
</body>
</html>
Preview
Clear
- Course Recommendations
- Courseware download
The courseware is not available for download at the moment. The staff is currently organizing it. Please pay more attention to this course in the future~
Students who have watched this course are also learning
Let's briefly talk about starting a business in PHP
Quick introduction to web front-end development
Large-scale practical Tianlongbabu development of Mini version MVC framework imitating the encyclopedia website of embarrassing things
Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]
Login verification and classic message board
Computer network knowledge collection
Quick Start Node.JS Full Version
The front-end course that understands you best: HTML5/CSS3/ES6/NPM/Vue/...[Original]
Write your own PHP MVC framework (40 chapters in depth/big details/must read for newbies to advance)
















