<!DOCTYPE HTML><HTMLLang= "en"> <Head> <MetaCharSet= "UTF-8"> <Metaname= "Generator"content= "EditPlus?"> <Metaname= "Author"content=""> <Metaname= "Keywords"content=""> <Metaname= "Description"content=""> <title>Baidu Map</title> <Scripttype= "Text/javascript"src= "Http://api.map.baidu.com/api?ak=PlhFWpA02aoURjAOpnWcRGqw7AI8EEyO&v=2.0&services=false"></Script> </Head> <Body> <style>Body, HTML{width:100%;Height:100%;margin:0;font-family:"Microsoft Jas Black";}#allmap{Height:500px;width:100%;} </style> <DivID= "Allmap"></Div> <Scripttype= "Text/javascript"> $(function(){ varMap= NewBmap.map ("Allmap"); var Point= NewBmap.point (116.501573, 39.900877); Map.centerandzoom (Point, -) //anchored Objects varGEOC= NewBmap.geocoder (); 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); //$ ("#start_point"). Val (r.point.lng+ ', ' +r.point.lat);Alert ("Current position longitude is:"+R.POINT.LNG+"Latitude is:"+R.point.lat); SetLocation (R.point); }Else { $("#start"). attr ("placeholder","Please enter your current location") Alert ('Unable to navigate to your current location, navigation failed, please enter your current location manually! '+ This. GetStatus ()); }},{enablehighaccuracy:true}); //get the location of the function functionsetlocation (point) {geoc.getlocation (point),function(RS) {varAddcomp=rs.addresscomponents; varresult=addcomp.province+addcomp.city+addcomp.district+Addcomp.street+Addcomp.streetnumber; //$ ("#start"). Val (result); //$ ("#start_location"). Val (result);Alert ("The current location is:"+result); }); } }); </Script> </Body></HTML>
Baidu Map API positioning the current location