HTML5 get the current location and show the example on the Baidu map __html

Source: Internet
Author: User
1.HTML5 get Current location

HTML5 geolocation API (Geographic application interface) to get the current location, mobile phone with GPS, computer based on the network location

Check to see if the browser supports the HTML5 geolocation API

<script type= "Text/javascript" >
if (navigator.geolocation) {
    alert (' Browser support geolocation! ');
} else{
    alert (' Browser does not support geolocation! ');
}
</script>

3 Call methods are provided

Gets the user's current location
void GetCurrentPosition (onsuccess, OnError, options);

Continues to obtain the user's current position, Showlocation represents the callback method
int watchposition (showlocation, OnError, options);

Cancellation of monitoring, Watchid for watchposition return value
void Clearwatch (Watchid);

Onsuccess after successful callback method (required)
OnError failed callback method (optional)
Options other parameters (optional)

Options = {
    enablehighaccuracy,//Boolean, require high-precision geo-information
    timeout,            //maximum latency, default 0 milliseconds
    maximumage          //Application cache time
}


2. Call Baidu Map Show

<! DOCTYPE html>  

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.