Nonsense don't say much, directly to everyone paste JS code. The specific code looks like this:
function Location () {};
Location.prototype.getLocation = function (callback) {var options = {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) can obtain the positioning Information object");
};
var self = this;
The IF (navigator.geolocation) {//browser supports geolocation navigator.geolocation.getCurrentPosition (function (position) {
Longitude var longitude = position.coords.longitude;
Latitude var latitude = position.coords.latitude;
Self.loadmapapi (Longitude,latitude);
}, Self.onerror, options);
else {//browser does not support geolocation}};
Location.prototype.loadMapApi = function (longitude, latitude) {var self = this;
var ohead = document.getElementsByTagName (' head '). Item (0);
var oscript= 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) {var point = new Bmap.point (longitude, latitude);
var gc = new Bmap.geocoder ();
Gc.getlocation (Point, Function (RS) {var addcomp = rs.addresscomponents;
Self.callback (Addcomp);
});
}
};
Location.prototype.onError = function (Error) {switch (error.code) {case 1:alert ("Location service denied");
Break
Case 2:alert ("temporary access to location information");
Break
Case 3:alert ("Get information timed out");
Break
Case 4:alert ("Unknown error");
Break
}
};
Call var local = new Location (); Local.getlocation (function (res) {//Here is the geographic information returned Console.log (res);})
The above is a small force to introduce the implementation of JavaScript based on the mobile phone location to obtain the current specific location (x province x, x County x Street x), I hope you like.