<script type= "Text/javascript" >functionLocation () {}; Location.prototype.getLocation=function(callback) {varOptions ={enablehighaccuracy:true, Maximumage:1000 }; This. Callback = Object.prototype.toString.call (callback) = = "[Object Function]"?Callback:function(address) {alert (address.province+address.city); Console.log ("Getocation (callbackfunction) to obtain positioning information objects"); }; varSelf = This; if(navigator.geolocation) {//Browser Support GeolocationNavigator.geolocation.getCurrentPosition (function(position) {//Longitude varLongitude =Position.coords.longitude; //Latitude varLatitude =Position.coords.latitude; Self.loadmapapi (longitude, latitude); }, Self.onerror, options); } Else { //Browser does not support geolocation } }; Location.prototype.loadMapApi=function(longitude, latitude) {varSelf = This; varOhead = document.getElementsByTagName (' HEAD '). Item (0); varOscript = document.createelement ("Script"); Oscript.type= "Text/javascript"; OSCRIPT.SRC= "http://api.map.baidu.com/getscript?v=2.0&ak=A396783ee700cfdb9ba1df281ce36862&services=&t= 20140930184510 "; Ohead.appendchild (Oscript); Oscript.onload=function(date) {varPoint =Newbmap.point (longitude, latitude); varGC =NewBmap.geocoder (); Gc.getlocation (Point,function(RS) {varAddcomp =rs.addresscomponents; Self.callback (Addcomp); }); } }; Location.prototype.onError=function(Error) {Switch(error.code) { Case1: Alert ("Location service is denied"); Break; Case2: Alert ("Cannot get location information temporarily"); Break; Case3: Alert ("Get information timed out"); Break; Case4: Alert ("Unknown Error"); Break; } }; //called varLocal =NewLocation (); Local.getlocation (function(res) {//here is the location information returnedConsole.log (RES); //json.stringify (RES), turn the returned object into a string, and intercept it on demand . varResstr =json.stringify (RES); alert (RESSTR); }); </script>
Put it on the mobile page
JS to achieve mobile page positioning