This article is a mirror article of machine translation, please click here to jump to the original article.

View: 13572|Reply: 0

[ionic] Ionic Development Android App Practice (4): Baidu Map API Positioning

[Copy link]
Posted on 7/4/2018 1:59:17 PM | | | |
Why not use the official _cordova-plugin-geolocation_ plugin for Android
The latest version of the plugin has removed the Android version of the positioning code, and the location is based on the system browser (chrome kernel).

The same question has been asked, and the author's answer is that it is faster and more accurate than native positioning.

But after testing, it was found that it could not be located at all, and after several investigations, it was found that it was related to what seemed to be a domestic network, and I believe everyone understands the reason, so I omitted a few words.

Baidu Map Positioning Cordova plug-in, supports Android, IOS, ionic 1x 2x can be used


cordova location plugin: cordova-plugin-baidumaplocation
GitHub address:https://github.com/aruis/cordova-plugin-baidumaplocation
ionic3 example:https://github.com/aruis/testbmap-cordova-ionic3

Test Environment:Huawei Honor 10 mobile phone (Android 8.1), ionic3

No nonsense, let's upload the renderings first:



Use the tutorial

1: Apply for Android and IOS version key, this step is omitted, please refer to the following to apply for Android key:

Baidu Maps applies for Android SDK key
https://www.itsvse.com/thread-4865-1-1.html
(Source: Architect_Programmer)
2: Install the plugin

UninstallPlugin commands:






If only the ANDROID_KEY is filled in, the error will be as follows:

(node:1204) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): CordovaError: Variable(s) missing (use: --variable IOS_KEY=value).
(node:1204) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

3: How to use

Add the following code under the android node of the project/platform/android/app/build.android file:




in the project\src\app\app.component.tsfile, replace the code as follows:

The error will be reported as follows when running on the web page, in fact, there is no need to worry.Directly package it as an apk and install it on your phone!!

Uncaught (in promise): ReferenceError: cordova is not defined
ReferenceError: cordova is not defined
    at http://localhost:8100/build/main.js:436:13
    at t.invoke (http://localhost:8100/build/polyfills.js:3:14976)
    at Object.onInvoke (http://localhost:8100/build/vendor.js:5134:33)
    at t.invoke (http://localhost:8100/build/polyfills.js:3:14916)
    at r.run (http://localhost:8100/build/polyfills.js:3:10143)
    at http://localhost:8100/build/polyfills.js:3:20242
    at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15660)
    at Object.onInvokeTask (http://localhost:8100/build/vendor.js:5125:33)
    at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15581)
    at r.runTask (http://localhost:8100/build/polyfills.js:3:10834)
Package it into an app, install it on the phone, and when you run it for the first time, it will prompt you to need location permissions, click Always Allow, as shown in the figure below:



For specific field content, please refer to:

BDLocation v7.2 for Android:http://wiki.lbsyun.baidu.com/cms/androidloc/doc/v7.2/index.html

BMKUserLocation v3.3.4 for IOS:http://wiki.lbsyun.baidu.com/cms ... 5c5554fe16aca1b4fbf





Previous:GET request "HTTP Error 400. The request URL is invalid"
Next:.NET Core uses the RSA encryption algorithm for error reporting solutions
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com