1. First introduce map.js on the page that needs to embed the map
<src= "http://api.map.baidu.com/api?v=2.0&ak= your secret key"></ Script>
2. Map positioning and displaying location information
//Baidu Map API featuresvarMap =NewBmap.map ("Allmap");varPoint =NewBmap.point (116.331398,39.897445); Map.centerandzoom (Point,12);varGeolocation =Newbmap.geolocation (); Geolocation.getcurrentposition (function(r) {if( This. getStatus () = =bmap_status_success) { varmk =NewBmap.marker (R.point); Map.addoverlay (MK); Map.panto (R.point); //alert (' Your location: ' +r.point.lng+ ', ' +r.point.lat '); varPoint =NewBmap.point (R.point.lng,r.point.lat);//find the location of the city streets and other information with the latitude and longitude of the location varGC =NewBmap.geocoder (); Gc.getlocation (Point,function(RS) {varAddcomp = rs.addresscomponents; Console.log (rs.address);//Address Information$ (' #place '). Append (rs.address)//alert (rs.address);//Popup Location }); } Else{alert (' Failed ' + This. GetStatus ()); }},{enablehighaccuracy:true})
Baidu Map API positioning + Display location