Baidu Map API locates the viewable area to its current location

Source: Internet
Author: User

1. Preface
It's always a little unaccustomed to say something at the beginning. Or say something, about Baidu map, I use the number of times or more, no way, demand ah. Well, when using Baidu map, there have been a lot of demand, but fortunately, Baidu map is very powerful, every need after exploration can meet the function. Baidu map in the future to meet some of the common functions of sorting out, but also convenient for some children's shoes reference. One of my projects is to start by positioning the viewable area of the map in its current position. Actually very simple, a lot of search on the Internet.
2. Details
Say more, rather than stick to the code more straightforward. But use Baidu map, must have AK. I don't think anyone knows that.
1. Introduction of JS File

1 <script type= "Text/javascript" src= "http://api.map.baidu.com/api?v1.5&ak= afb5d4d8279a19b2fc3a16d063f26772 "></script>

2.html Code Layout

<id= "Allmap"  styleheight:500px; ' ></ Div >

3.js Code

var New Bmap.map ("Allmap"); var New bmap.geolocation (); geolocation.getcurrentposition (function  (r) {    if ( this. GetStatus () = = bmap_status_success) {        map.centerandzoom (new Bmap.point ( R.POINT.LNG, R.point.lat);     true })

4. After running the HTML, you can see the Baidu map is located in your current location. Some browsers will pop up the message "Want to get your location" and remember to click "Allow".

3. Summary

Well, it seems to be so simple, you can try it yourself. There will be more to write about my use of Baidu map problems and solutions, as well as the recent use of Baidu Eagle eye related.

Baidu Map API locates the viewable area to its current location

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.