Blogger Information
Blog 47
fans 0
comment 2
visits 102674
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
h5+plus检查手机上是否已经安装了百度地图、腾讯地图、高德地图,如果安装了就打开地图并导航过去
拾一枝樱花的博客
Original
2551 people have browsed it
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <title>Document</title>
  6. <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  7. <link rel="stylesheet" type="text/css" href="../lib/css/mui.css" />
  8. </head>
  9. <body>
  10. <header class="mui-bar mui-bar-nav">
  11. <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
  12. <h1 class="mui-title">地图</h1>
  13. </header>
  14. <div class="mui-content">
  15. <button id="nav" onclick="nav">开始导航</button>
  16. </div>
  17. <script src="../lib/js/mui.min.js" type="text/javascript" charset="utf-8"></script>
  18. <script type="text/javascript">
  19. mui.init()
  20. mui.plusReady(function() {
  21. //传入包名,检查手机上是否安装了这个应用
  22. function isInstall(packageName) { //
  23. try {
  24. var main = plus.android.runtimeMainActivity();
  25. var packageManager = main.getPackageManager();
  26. var PackageManager = plus.android.importClass(packageManager);
  27. var packageinfo = packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES)
  28. if (packageinfo) {
  29. return true;
  30. } else {
  31. return false;
  32. }
  33. } catch (e) {
  34. return false;
  35. }
  36. }
  37. //批量传入包名,检查一系列应用是否安装,如果有任意一个安装了,就执行success,否认执行fail
  38. function operationAfterCheckInstall(mapsPackageNames, success, fail) {
  39. var res = mapsPackageNames.map(function(item) {
  40. return isInstall(item);
  41. })
  42. if (eval(res.join("||"))) {
  43. success();
  44. } else {
  45. fail();
  46. }
  47. }
  48. //可以在这里写业务逻辑了
  49. document.getElementById("nav").onclick = function() {
  50. //如果还知道其他地图的包名,也可以放这个数组里
  51. var mapsPackageNames = ['com.baidu.BaiduMap', 'com.autonavi.minimap', 'com.tencent.map'];
  52. operationAfterCheckInstall(mapsPackageNames, function() {
  53. var dst = new plus.maps.Point(46.1757500000,129.4252800000); // 目的地
  54. var src = new plus.maps.Point(116.335, 39.966); // 起始地 可以不填
  55. plus.maps.openSysMap(dst, "达连河", src);
  56. }, function() {
  57. alert("您未安装百度地图、高德地图、腾讯地图,请前往应用市场下载");
  58. })
  59. }
  60. })
  61. </script>
  62. </body>
  63. </html>
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
2 comments
拾一枝樱花 2021-02-05 15:53:16
mui官网下载即可
2 floor
? 2021-01-11 11:09:05
/lib/js/mui.min.js,请问你这个js在哪
1 floor
Author's latest blog post