JavaScript embedded into Baidu Map
After applying for the corresponding key on the Baidu map API official website, you can embed Baidu map online in JavaScript.
<Script type = "text/javascript" src = "http://api.map.baidu.com/api? V = 2.0 & ak = Key "> </script>
Create a map instance
Var map = new BMap. Map (); // create a map instance
Show Map
Map = new BMap. map ("map_canvas"); // create a Map instance var point = new BMap. point (112.931, 28.169); // create Point Coordinate map. centerAndZoom (point, 15); // initialize the map and set the coordinates of the center and map level. enableScrollWheelZoom ();
Display map controls:
// Display map control map. addControl (new BMap. mapTypeControl ({mapTypes: [BMAP_NORMAL_MAP, BMAP_HYBRID_MAP]}); // 2D map, satellite map. addControl (new BMap. mapTypeControl ({anchor: BMAP_ANCHOR_TOP_RIGHT}); // in the upper left corner, the default map control is map. setCurrentCity ("Changsha"); // you need to set the city because of the 3D image. // Add the zoom control map. addControl (new BMap. navigationControl (); // Add the default zoom and Pan control // Add the map of the scale control. addControl (new BMap. scaleControl ({anchor: BMAP_ANCHOR_BOTTOM_LEFT}); // lower left