I think in the era of wood provides a map interface, front-end engineers either write only the specific address of the enterprise, or use a map image labeled with their own location. But it's not the same now! In order to enhance the user experience, Google, and even Baidu are very open, you can find the map interface on their website, by making a direct call to it.
Below I will teach you how to use Baidu map in the Web page, of course, you can also go to Baidu Map website to find relevant technical information.
First you need to enter the Baidu Map official website http://developer.baidu.com/map/ . Because we are loading with a script, so we have to choose the first "JavaScript API" in, you will find that it has a very powerful function of wood?
This is just the tip of its iceberg. You can "start experiencing" at the bottom. There is the source code, you can get it, and then put it into your Web page. But what I'm talking about today is not so simple.
What I need is the map layer, the need to move, and the ability to navigate the search function. How to achieve it? Copy the following code into your Web page:
<script type= "Text/javascript" >// Baidu Map API function Var map = new bmap.map (' map '); Var poi = new bmap.point (116.307852,40.057031); Map.centerandzoom (poi, 16); Map.enablescrollwheelzoom ();var content = ' <div style= ' margin:0;line-height:20px; padding:2px; " > ' + ' ' + ' Address: No. 10th, 10 Street, Haidian District, Beijing <br/> Tel: (010) 59928888<br/> Introduction: Baidu Building is located in Haidian District, Beijing, West Two flags Metro station, for the company's comprehensive research and Development and office headquarters. ' + ' </div> ';//create a Retrieve Information window object Var searchinfowindow = null;searchinfowindow = new bmaplib.searchinfowindow (map, content, {title : "Baidu Mansion", //title width : 290, //width height : 105, //height panel : "Panel", //Search Results Panel enableautopan : true, //Auto Pan searchtypes :[bmaplib_tab_search, //around search bmaplib_tab_to_here, //here to Bmaplib_tab_ from_here //from here]}); Var marker = new bmap.marker (POI); // Create marker object marker.enabledragging (); //marker can drag Marker.addeventlistener ("click", function (e) { Searchinfowindow.open (marker);}) Map.addoverlay (marker); //add Markersearchinfowindow.open (marker) to the map and //on marker open the retrieve information serial port $ ("close"). Onclick = function () {searchinfowindow.close ();} $ ("open"). Onclick = function () {var enablesendtophone = false;if ($ (" Enablesendtophone "). checked) {enablesendtophone = true;} Searchinfowindow = new bmaplib.searchinfowindow (map, content, {title : "Baidu Tower", //title width : 290, //width height : 105, //height panel : "Panel", //Search Results Panel enableautopan : true, // Auto Pan enablesendtophone: enablesendtophone, //is enabled to send to phone searchtypes :[bmaplib_tab_ search, //around search bmaplib_tab_to_here, //to get here bmaplib_tab_from_here //from here]}); if ($ ("Enableautopan"). Checked) {searchinfowindow.enableautopan ();} else {searchinfowindow.disableautopan ();}; Searchinfowindow.open (marker);} $ ("show"). Onclick = function () {searchinfowindow.show ();} $ ("Hide"). Onclick = function () {searchinfowindow.hide ();} $ ("GetPosition"). Onclick = function () {var position = Searchinfowindow.getposition (); Alert ("Longitude:" + position.lng + "; Latitude:" + Position.lat);} $ ("SetValue"). Onclick = function () {searchinfowindow.setposition (New bmap.point ("LNG"). Value, $ ("Lat"). value); Searchinfowindow.settitle ($ ("title"). Value); Searchinfowindow.setcontent ($ ("content"). value);} $ ("GetContent"). Onclick = function () {alert (searchinfowindow.getcontent ());} $ ("GetTitle"). Onclick = function () {alert (Searchinfowindow.gettitle ());} function $ (ID) {Return document.getelementbyid (id);} Style 1var searchinfowindow1 = new bmaplib.searchinfowindow (map, "info box 1 Contents", {title: Info box 1″, //title panel : "Panel", //search results Panel enableautopan : true, // Auto-pan searchtypes :[bmaplib_tab_from_here, //from here bmaplib_tab_search //Peripheral Search]}); Function openinfowindow1 () {searchinfowindow1.open (New bmap.point (116.319852,40.057031));} Style 2var searChinfowindow2 = new bmaplib.searchinfowindow (map, "Information box 2 Content", {title: "information box 2″, //title panel : "Panel", //search results panel enableautopan : true, //Auto Pan searchtypes : [Search around bmaplib_tab_search //]}); Function openinfowindow2 () {searchinfowindow2.open ( New bmap.point (116.324852,40.057031));} Style 3var searchinfowindow3 = new bmaplib.searchinfowindow (map, "info box 3 Contents", {title: info box 3″, //title width: 290, //width height: 40, //height panel : "Panel", // Search Results Panel enableautopan : true, //Auto Pan searchtypes :[]}); FUNCTION&NBSP;OPENINFOWINDOW3 () { Searchinfowindow3.open (New bmap.point (116.328852,40.057031));} var ispanelshow = false;//Display Results Panel action $ ("Showpanelbtn"). Onclick = function () {if ( Ispanelshow == false) {ispanelshow = true;$ ("showpanelbtn") .style.right = " 300px "; $ (" Panelwrap") .style.width = " 300px "; $ (" map ") .style.marginright = " 300px "; $ (" showpanelbtn "). InnerHTML = "Hide search results panel <br/>>";} else {ispanelshow = false;$ ("showpanelbtn") .style.right = "0px"; $ ("PanelWrap"). style.width = "0px"; $ ("map") .style.marginright = "0px"; $ ("showpanelbtn"). innerhtml = "Show search results panel <br/><";}} </script>
don't think this is OK, and these are also needed drops!
The box used to install the map, use the id= "map" in the box, and the JS library .
<script type= "Text/javascript" src= "http://api.map.baidu.com/api?v=1.5&ak= 2b866a6daac9014292432d81fe9b47e3 "></script>
Look at the effect:
Here are some places that can be changed var poi = new Bmap.point (116.307852,40.057031), a coordinate point used to modify your location on the map, Map.centerandzoom (POI, 16), which can be used to display the map layer, Scroll your pulley on the map and you'll see.
What if I don't know the coordinates of my specific location or if I want to make the location more precise?
You can pick the tool with coordinates, or use the Quick build tool
What do you think? Is this kind of user experience quite a blast?
What we need to know, however, is that there is also a loss when it comes to a good experience for the user. The use of external loading will let our web page open speed down.
If you still have what do not understand, can leave a message Oh!
original link:http://www.qianduanview.com/237.html
How to call Baidu Map API in a webpage