Use of Baidu map js and Baidu map js

Source: Internet
Author: User

Use of Baidu map js and Baidu map js
Display map and location information on the webpage. You can use Baidu map. See http://developer.baidu.com/map/index.php? Title = jspopular/guide/introduction
1. Get the key and secret key to be used in js reference of Baidu map api. My key is 127fi2f04wxavuwmgu8fn49kl1234567890.

<Script src = "http://api.map.baidu.com/api? V = 1.5 & ak = your key "type =" text/javascript "> </script>
2. Place the <div> container with the specified id in html
<div id="baiduMap"></div>
3. Set css
Html, body {width: 100%; height: 80%;}/* both html and body cannot be less */# baiduMap {width: 100%; height: 80%; overflow: hidden; margin: 0.1em ;}
4. Compile js Code
Function baiduMap () {var map = new BMap. map ("baiduMap"); // allmap is the idvar point of the div label = new BMap. point (121.421088, 31.20956); // coordinates of the yan'an West Road campus of Donghua University-Longitude and latitude map. centerAndZoom (point, 16); // The point-centric scaling level is 16var navigationControl = new BMap. navigationControl (); map. addControl (navigationControl); // Add a navigation control to achieve drag, translation, and scale map. enableScrollWheelZoom (true); // allows the mouse wheel to zoom in and out var scaleControl = new BMap. scaleControl (); map. addControl (scaleControl); // Add the scale display control var marker = new BMap. marker (point); // creates a map annotation. addOverlay (marker); // Add the annotation to the map marker. setAnimation (BMAP_ANIMATION_BOUNCE); // specifies the animation var label = new BMap. label ("here I am", {// offset between TAG content and tag offset: new BMap. size (20,-10)}); marker. setLabel (label );}

Effect

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.