Statement: The material used in this column is written by the VIP students of the Kay Academy, who has the right to be anonymous and has the final right to interpret the article; The Edith Academy is designed to promote students to learn from each other on the basis of public notes.
GPS positioning
There is a geolocationapi in HTML5, which is used to obtain the user's geographic location via GPS, which is commonly known as GPS positioning. Since this feature may infringe the privacy of the user, the user location information is not available unless the user consents.
The user's location needs to be obtained through the GetCurrentPosition () method, which has two parameters, the first to execute the code that obtains the geolocation, and the second to handle the error. It specifies the function that runs when the user location fails. code example:
Operation Result:
The browser asks if the location is allowed, throws an error object if it is not allowed, and then executes the error handler to handle it accordingly:
If the process of obtaining a geography error occurs, an error handler is also executed to print out the appropriate error type:
You can also locate on your phone:
In addition, you can call some map APIs to display coordinates on the map. The code example, I call here is the Baidu Map API:
Operation Result:
Html5-gps positioning