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&TID=121352&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