Resolution of coordinate deviations in the use of Baidu Map API in the development of hybrid apps

Source: Internet
Author: User

Use Ngcordova's $cordovageolocation module in your project to get the current position latitude and longitude, When displayed in the Baidu map when found error (my test error is about 1.7 km), check the data found that Baidu map latitude and longitude and ordinary GPs obtained latitude and longitude is not the same, the solution reference Baidu Open Map Forum official sticker (http://bbs.lbsyun.baidu.com/ FORUM.PHP?MOD=VIEWTHREAD&AMP;TID=121352&AMP;EXTRA=PAGE%3D1). I use the official give the second way, the code reference is as follows: Ionic framework, introducing <script src= "http://api.map.baidu.com/api?v=2.0&ak= your Key" ></script > and inject the code inside the Ngcordova;controller into the app as follows:
varLatLong;varPosoptions = {enablehighaccuracy:true};//Set positioning accuracy$cordovaGeolocation. GetCurrentPosition (posoptions). Then (function(position) {varLo=position.coords.longitude;//Longitude    varLa=position.coords.latitude;//Latitude    //Start conversion coordinates (GPS---baidu coordinates)$http ({method:' GET ', URL:' http://api.map.baidu.com/geoconv/v1/?coords= ' +lo+ ', ' +la+ ' &from=1&to=5&ak= your secret key '}). Then (functionSuccesscallback (response) {//Conversion Complete      Long=response.data.result[0].x; Lat=response.data.result[0].y; //Call Baidu Map API display   varMap =NewBmap.map ("Map"); varPPoint =NewBmap.point (Long, LAT); Map.centerandzoom (PPoint,18); varGEOC =NewBmap.geocoder (); varmk =NewBmap.marker (ppoint); Map.addoverlay (MK); Geoc.getlocation (NewBmap.point (Long, LAT),function(RS) {if(RS) {varlocation=rs.addresscomponents; $scope. mylocation=location.province+location.city+location.district+location.street+location.streetnumber+ Rs.surroundingpois[0].title;  Console.log ($scope. mylocation);    }}); }, functionErrorcallback (response) {Window.alert ("Failed to convert coordinates, please check network")    }); }, function(Err) {Window.alert ("Get Geo Failed")  });

The above content is original, if have mistake, hope to point out, thank

Resolution of coordinate deviations from the Baidu map API during the hybrid app development process

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.