HTML5-GPS positioning

Disclaimer: The materials used in this column are written by VIP students of Kaige Academy. Students have the right to remain anonymous and have the right to final interpretation of the article. Kaige Academy aims to promote VIP students to learn from each other based on public notes.

GPS positioning

There is a Geolocation API in html5, which is used to obtain the user's geographic location through GPS, which is commonly known as GPS positioning. Given that this feature may violate user privacy, user location information is not available unless the user agrees.
The user's location needs to be obtained through the getCurrentPosition() method, which has two parameters, the first is used to execute the code to get the location, and the second is used to handle errors. It specifies a function to run when getting the user's location fails. Code example:

image

image

Running result: The
browser will ask whether to allow positioning. If you click not allowed, an error object will be thrown, and then the error handling function will be executed for corresponding processing:

image

If there is an error in the process of obtaining the geographic location, the error handling function will also be executed, and the corresponding error type will be printed:

image

It can also be located on the mobile phone:

image

In addition, some map APIs can be called to display the coordinates on the map. Code example, I am calling the API of Baidu Maps here:

image

operation result:

image

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326671582&siteId=291194637