The first contact of Baidu map API and the first contact of map api

Source: Internet
Author: User

The first contact of Baidu map API and the first contact of map api

Due to project requirements, Baidu API was first introduced.

 

Step 1: reference the Baidu map API script

If you want to download both the map file and js file in the LAN environment

  

<script type="text/javascript"  src="http://api.map.baidu.com/api?key=*****************&v=1.0&services=false"></script>

 

You need to go to the Baidu Developer Center to apply for a KEY.

Step 2: Create a div named by you to put the map

<div style="width: 520px; height: 340px; border: 1px solid gray" id="container"></div>

 

Step 3: use Baidu map API to build a map

// Initialize the map and place the map in the div of step 2.
Var map = new BMap. Map ("container ");
// Determine a point based on the longitude and latitude
Var point = new BMap. Point (116.404, 39.915 );
// This is the point in the map center, and the zoom-in level of the map is set to 15map. centerAndZoom (point, 15 );
// The interface is moved to the center 2 s later to a new window. setTimeout (function () {map. panTo (new BMap. Point (116.409, 39.918);}, 2000 );
// Load some controls on the Interface: Zoom control, scale control, and global control map. addControl (new BMap. navigationControl (); map. addControl (new BMap. scaleControl (); map. addControl (new BMap. overviewMapControl ());
// Add an identifier var marker = new BMap. Marker (point); map. addOverlay (marker );

Step 4: connect to the Internet and open it in a browser

 

Related Article

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.