"Baidu Map" analysis of how to use Baidu map

Source: Internet
Author: User

Overview

Readers need to apply for a key before using the Baidu maps API, and readers can click here to read a detailed tutorial on the Baidu map JavaScript API.

Baidu map JavaScript API syntax

The syntax for Web development is JavaScript.

JavaScript class Reference

Click I read the JavaScript class reference.

A simple map Demo

<!DOCTYPE HTML><HTML>  <Head>    <title>Demo</title>            <Metaname= "Content-type"content= "text/html; charset=utf-8">        <!--In order to better support the mobile terminal -        <Metaname= "Viewport"content= "initial-scale=1.0, User-scalable=no" />    <!--reference Baidu Map API JS -    <Scriptsrc= "HTTP://API.MAP.BAIDU.COM/API?V=2.0&AK=UFUZJKLXJF6BMZVIIDW9C5HJDGVTO9BW"></Script>      </Head>  <Body>  <!--must set width and height -  <DivID= "Container"style= "width:70%;height:400px"></Div>  <Script>    //Create Map    varMap=NewBmap.map ("Container"); //Initialize Map    varpoint1=NewBmap.point (104.074091,30.665783); Map.centerandzoom (Point1, A); //add marker on map    varPoint2=NewBmap.point (104.158603,30.642172); varMarker=NewBmap.marker (Point2);        Map.addoverlay (marker); //Addpanoramaconveragelayer on Map    varPclyer=NewBmap.panoramacoveragelayer ();        Map.addtilelayer (Pclyer); //add Panoramacontrol on map    varPNRM=NewBmap.panoramacontrol ();        Map.addcontrol (PNRM); //add Overviewcontrol on map    varOverviewcontrol= NewBmap.overviewmapcontrol ({anchor:bmap_anchor_bottom_right,isopen:true});      Map.addcontrol (Overviewcontrol); </Script>  </Body></HTML>

Summarize:

    1. Your own keys can be viewed in the API console.
    2. BMap is the namespace for the entire JavaScript API, and all JavaScript API classes must be preceded by the "BMap.", which requires a different namespace to refer to a class other than the JavaScript API.
    3. Most classes in the JavaScript API have listener events, so you can listen through AddEventListener ():
      Map.addeventlistener ("click", Function (e) {  console.log (e.point.lng+ "," +e.point.lat);});
    4. The function arguments in AddEventListener () can have the following properties:
      1. E.point.lng
      2. E.point.lat
      3. E.pixel.x
      4. E.pixel.y
      5. E.bounds
      6. E.size

"Baidu Map" analysis of how to use Baidu map

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.