Call Baidu Map API to achieve mobile phone automatic positioning (inverse address resolution)

Source: Internet
Author: User

    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)

Related Article

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.