Ionic add Baidu map positioning plugin Cordova-plugin-baidu-geolocation.git

Source: Internet
Author: User

This plug-in is suitable for directly invoking the positioning function (including WiFi, base station, GPS) in the JS Code of Ionic Project, returning the location information of the specified coordinate system and supporting the location tracking.
The steps are as follows:
1, if the computer does not have Git installed, please first install git, the official download link:
Https://git-scm.com/download/win

2, enter the Ionic project directory and execute the following command:

Cordova Plugin Add https://github.com/ETENG-OSP/cordova-plugin-baidu-geolocation.git--variable api_key= Baidu assigned AK-- Save

3, if the project has been added to the Android or iOS platform, removed and then added, if not added platform is ignored.

Ionic Remove platform Android
Ionic remove platform iOS
Ionic add platform Android
ionic add platform iOS

4. Add the configuration to the Config. Ionic project in the file.

  <!--Android using this plugin--
  <platform name= "Android" > ...
    <plugin name= "cordova-plugin-baidu-geolocation" spec= "https://github.com/ETENG-OSP/ Cordova-plugin-baidu-geolocation ">
      <variable name=" Api_key "value=" Baidu assigned AK "/>
    </plugin>
    ......
  </platform>

  <!--iOS using the official plugin--
  <platform name= "ios" >
    ...
    <plugin name= "cordova-plugin-geolocation" spec= "~1.0.0"/>
    ...
  </platform>

Baidu Map of the Api_key, before use need to apply for application in Baidu, get api_key. If you fill in the wrong way, you can only use GPS to locate the base station and WIFI.

5, in the project JS code to use, direct paste code:

if (navigator.geolocation) {navigator.geolocation.getCurrentPosition (function (position) {var point
            = new Bmap.point (position.coords.longitude, position.coords.latitude); if (ionic. Platform.isios ()) {//To determine if the terminal is iOS, if it is iOS, coordinate conversion (iOS is not returned by Baidu Map coordinate system) var convertor = new Bmap.conver
              Tor ();
              var pointarr = [];
              Pointarr.push (point); Convertor.translate (Pointarr, 0, 5, function (data) {if (data.status = = = 0) {//Get to BD09LL
                coordinate system coordinates var locationpoint = new Bmap.point (DATA.POINTS[0].LNG, Data.points[0].lat);
            }
              });
          }else{//Android directly obtains the coordinates of the bd09ll coordinate system, does not need to convert}}, function (Error) {//Location failure related actions }, {coortype: ' bd09ll ', maximumage:3000, timeout:2000, Enablehi
        Ghaccuracy:true}); }else {//NoneMethod using Navigator.geolocation to locate related actions} 

About configuration Item Information interpretation:

  Coortype: ' Bd09ll ',         //default is GCJ02, can fill bd09ll to get Baidu latitude and longitude for access to Baidu API
  maximumage:3000,         //cache time
  timeout:2000,< c5/>//Timeout Time
  enablehighaccuracy:true  //whether using GPS

6, if you need to continuously track the user location:

Navigator.geolocation.watchPosition (success, [ERROR], [options]);

Note: If you use the SDK23 version for packaging, you should be aware that On the latest android6.0, and the previous authorization mechanism has been different, if the use of 23 version of the package, running on more than android6.0 mobile phone will not give the access to the location of the pop-up windows, must be changed to 23 to compile the version

Resources:
Https://github.com/ETENG-OSP/cordova-plugin-baidu-geolocation/blob/master/README.md
http://blog.csdn.net/sean_css/article/details/52248190

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.

Tags Index: