我正在研究IONIC 3,现在正在开发一个使用usig Google Maps API的应用程序。问题是我正在尝试执行我的应用程序,但是当它启动时,会出现以下消息:
inicio.html
Error: Uncaught (in promise): TypeError: Cannot read property
'nativeElement' of undefined
TypeError: Cannot read property 'nativeElement' of undefined
Run Code Online (Sandbox Code Playgroud)
这是产生问题的代码:
inicio.ts(仅是代码的一部分)
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);
});
}
Run Code Online (Sandbox Code Playgroud)
inicio.ts(完整代码)
import { Component,ViewChild, ElementRef } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Geolocation } from '@ionic-native/geolocation';
import …Run Code Online (Sandbox Code Playgroud) 你好吗?。我正在学习带有 Ionic 3 教程的 Google 地图。我已经完成了那里解释的所有内容,但是当项目启动时,出现了这个错误。我已经调查了很多,但没有任何效果。谢谢!。
Error: Uncaught (in promise): ReferenceError: google is not defined
ReferenceError: google is not defined
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
家.ts
import { Component, ViewChild, ElementRef } from '@angular/core';
import { NavController } from 'ionic-angular';
import { IonicPage } from 'ionic-angular';
declare var google;
@IonicPage()
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
@ViewChild('map') mapElement:ElementRef;
map: any;
start = 'chicago, il';
end = 'chicago, il';
directionsService = new google.maps.DirectionsService;
directionsDisplay = new google.maps.DirectionsRenderer;
constructor(public navCtrl: NavController) { …Run Code Online (Sandbox Code Playgroud) 我将Android Studio更新为2.3.1.现在,当我尝试通过图形模式编辑布局时,组件树和调色板在任何地方都不可见.我在谷歌搜索过多,我找不到解决问题的方法.感谢您的时间和关注.请原谅我可怜的英语.