<script type= "Text/javascript" src= "js/bmap.js" ></script> <script type= "Text/javascript" >//whether the extension API is ready, and if not, listen for "Plusready" events if(window.plus) {plusready (); }Else{Document.addeventlistener ("Plusready", Plusready,false ); } //What to do when the extension API is ready to complete functionPlusready () {varMap =NewBmap.map ("Allmap"); varlongitude, latitude; Navigator.geolocation.getCurrentPosition (function(position) {Longitude=Position.coords.longitude; Latitude=Position.coords.latitude; }); SetTimeout (function () { varGpspoint =Newbmap.point (longitude, latitude); BMap.Convertor.translate (Gpspoint,0,function(point) {varGEOC =NewBmap.geocoder (); Geoc.getlocation (Point,function(RS) {varAddcomp =rs.addresscomponents; Alert (addcomp.province+ "," + addcomp.city + "," + Addcomp.district + "," + Addcomp.street + "," +addcomp.streetnumber); }); }); }, 3000); } </script>
Bmap.js:
(function() {window. Bmap_loadscripttime= (NewDate). GetTime (); document.write (' <script type= ' Text/javascript "src=" http://api.map.baidu.com/getscript?v=1.3 "></script>"); document.write (' <link rel= ' stylesheet "type=" Text/css "href=" Http://api.map.baidu.com/res/13/bmap.css "/>"); //2011-7-25 functionLoad_script (Xyurl, callback) {varHead = document.getElementsByTagName (' head ') [0]; varScript = document.createelement (' script '); Script.type= ' Text/javascript '; SCRIPT.SRC=Xyurl; //using the script cross-domain method of jqueryScript.onload = Script.onreadystatechange =function(){ if((! This. readyState | | This. readyState = = = "Loaded" | | This. readyState = = = "complete") ) {callback&&callback (); //Handle memory leak in IEScript.onload = Script.onreadystatechange =NULL; if(Head &&script.parentnode) {head.removechild (script); } } }; //Use insertbefore instead of AppendChild to circumvent an IE6 bug.head.insertbefore (script, head.firstchild); } functionTranslate (point,type,callback) {varCallbackname = ' Cbk_ ' + math.round (math.random () * 10000);//The name of the random function varXyurl = "http://api.map.baidu.com/ag/coord/convert?from=" + type + "&to=4&x=" + point.lng + "&y=" + Point.lat + "&callback=bmap.convertor." +Callbackname; //dynamically create a script tagLoad_script (Xyurl); Bmap.convertor[callbackname]=function(xyresult) {DeleteBmap.convertor[callbackname];//need to delete the modified function after the call varPoint =NewBmap.point (Xyresult.x, XYRESULT.Y); Callback&&callback (point); }} window. BMap= window. BMap | | {}; Bmap.convertor= {}; BMap.Convertor.translate=translate;}) ();
HTML5 mobile to get detailed address according to Baidu Map API