Html5-gps positioning

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.