JS to achieve mobile page positioning

Source: Internet
Author: User

<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

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.