首页 文章

如何在Ionic 2上使用非原生mapbox插件?

提问于
浏览
0

我正在尝试使用名为 Mapbox 的非原生Ionic 2插件 . 参考站点是Telerik Mapbox,我做了以下步骤:

  • 我通过 cordova plugin add ... 安装它

  • 在我要渲染原生 Map 的页面上,我在顶部声明了 declare var cordova: any;

  • 最后调出方法来显示 Map

if (typeof cordova !== 'undefined') {
  cordova.plugins.Mapbox.show(
  {...})
}else{
  console.log("cordova is undefined");
}

返回的错误是:

无法读取未定义的属性'show'

离子 - > 3.5.2

科尔多瓦 - > 7.0.1

为什么不认识他的方法?

EDIT

我可以通过下载repo并添加它来安装mapbox插件 ionic cordova plugin add /path/to/my/plugin/my.plugin.folder.here/ .

现在问题总是与上面描述的相同 . 如果相反,我声明全局Mapbox declare var Mapbox: any; 然后调用它

if (typeof cordova !== 'undefined') {
  Mapbox.show(
    {...})
}else{
console.log("cordova is undefined");
}

该应用程序崩溃了 .

1 回答

  • 0

    使用 window.plugins.PLUGIN_NAMe 访问非native / corodva插件 .

    import { Platform } from 'ionic-angular';
    
    @Component({...})
    export MyPage {
      constructor(public plt: Platform) {
        if (this.plt.is('cordova')) { 
            window.plugins.Mapbox.show(
            {...})
        }
      }
    }
    

相关问题