【问题标题】:Error: Uncaught (in promise): ReferenceError: google is not defined in ionic 3错误:未捕获(承诺):ReferenceError:谷歌未在离子3中定义
【发布时间】:2017-06-20 18:21:59
【问题描述】:

我正在尝试在我的应用中包含谷歌地图。但我没有得到 google is not defined 错误。 我已经添加了插件

ionic plugin add cordova-plugin-geolocation
npm install --save @ionic-native/geolocation

我的代码是这样的:

ionViewDidLoad(){
    this.loadMap();
  }
  loadMap(){

    this.geolocation.getCurrentPosition().then((position) => {

      let latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

      let mapOptions = {
        center: latLng,
        zoom: 15,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      }

      this.map = new google.maps.Map(this.mapElement.nativeElement, mapOptions);

    }, (err) => {
      console.log(err);
    });

  }

有人可以帮我解决这个问题吗?

【问题讨论】:

  • 你是如何加入谷歌地图的? javascript 库还是 ionic 原生插件?

标签: cordova google-maps ionic3


【解决方案1】:

您安装的插件 (cordova-plugin-geolocation) 只是为您提供了用户位置。它不包含 Google Maps API。

要使用 Google 地图,您可以:

【讨论】:

    猜你喜欢
    • 2018-01-31
    • 2014-06-05
    • 2014-09-02
    • 2020-02-29
    • 2021-11-08
    • 2022-06-15
    • 1970-01-01
    • 2017-10-05
    • 2018-08-26
    相关资源
    最近更新 更多