Declaration Address Resolver var GEOC = new Bmap.geocoder (); Auto-position var autolocation = function () {if (navigator.geolocation) {//To determine if the browser can get the current position Navigator.geolo Cation.getcurrentposition (ADDRSUC, Addrfail); } else {Simplenoty ("cannot be automatically located, please enter your dining address"); }}//Gets the current coordinate success function addrsuc (param) {var lng = param.coords.longitude; var lat = param.coords.latitude; var point = new Bmap.point (LNG, LAT); Convert GPS coordinates to Baidu address coordinates BMap.Convertor.translate (point, 0, Translatecallback); }//Get coordinates failed function Addrfail (err) {shownotify ("Auto location failed"); }//Coordinate conversion function Translatecallback (point) {geoc.getlocation (point, Function (RS) {V Ar addcomp = rs.addresscomponents; Query the resulting Address object component//addcomp.streetnumber: Street number//addcomp.city: City//addcomp.district: District Addcomp.street: Street//addcomp.province: province var address = Addcomp.city + addcomp.district + addcomp.street; var lng_t = point.lng; Longitude var lat_t = Point.lat; Latitude $ (". Locationtxt"). Text ("Current position:" + address); }) }
Examples of objects:
Rs object: {point:h, Address: "Guang Shun North Street, Chaoyang District, Beijing", Addresscomponents:object, Surroundingpois:array[0], business: "Wangjing, to Canton Camp, Flower Home"}ad Dresscomponents object: {streetnumber: "", Street: "Guang Shun North Street", District: "Chaoyang District", City: "Beijing", Province: "Beijing"}
Call:
$ (function () { aotulocation ();});
Call Baidu Map API to achieve mobile phone automatic positioning (inverse address resolution)