How does HTML5 get the location of website visitors
This article mainly introduces the relevant knowledge of "how to obtain the location of website visitors by HTML5". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope that this article "how to obtain the location of website visitors by HTML5" can help you solve the problem.
Looking for the coordinates of visitors.
Using HTML5 geolocation API to get site visitors' location information is very simple. It makes use of the objects wrapped into these three methods navigator.geolocation-getCurrentPosition (), watchPosition (), and clearWatch ().
First, you need to agree to let the browser tell the Web server where you are.
Try this code for example »
Get Current Position
Function showPosition () {
If (navigator.geolocation) {
Navigator.geolocation.getCurrentPosition (function (position) {
Var positionInfo = "Your current position is (" + "Latitude:" + position.coords.latitude + "," + "Longitude:" + position.coords.longitude + ")"
Document.getElementById ("result") [xss_clean] = positionInfo
});
} else {
Alert ("Sorry, your browser does not support HTML5 geolocation.")
}
}