我正在尝试将googlemaps实施到我的angular-cli项目中.我知道有一个'angular2-google-maps'组件(github),但我需要路由和更多自定义功能.
我找到了两种将地图实现到项目中的方法:
1:stackoverflow:使用谷歌api加载器 - 但我无法弄清楚如何初始化谷歌地图...
2:使用DefinitelyTyped google.maps.d.ts.我用--global安装它(因为环境已被弃用..)到我的项目中并将index.d.ts(用于全局)添加到src/typings.d.ts并且可以使用"google.map .." .ts文件:
myLatLng = {lat: -25.363, lng: 131.044};
map:any;
constructor() {
this.map = new google.maps.Map(document.getElementById('map'), {
center: this.myLatLng,
zoom: 4
});
}
Run Code Online (Sandbox Code Playgroud)
但如果我用angular-cli构建它就会出错:"ReferenceError:google is not defined"
有任何想法吗?