HTML5 mobile to get detailed address according to Baidu Map API

Source: Internet
Author: User

<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

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.