使用谷歌地图JavaScript应用程序接口,我似乎无法在离子应用程序上显示地图。
到目前为止,我已经尝试了google.maps.event.trigger(map, 'resize'),因为我已经更改了地图分区的宽度。从解决方案here中看到了这一点。仅供参考,地图过去工作得很好,但当我尝试平移时出现了一些小故障。
在map.component.ts中
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { google } from 'google-maps';
@Component({
selector: 'app-map',
templateUrl: './map.component.html',
styleUrls: ['./map.component.scss'],
})
export class MapComponent implements OnInit {
// Map setup
@ViewChild('mapElement', {static: true}) mapElement: ElementRef<HTMLElement>;
map: google.maps.Map;
constructor() {
}
ngOnInit() {
console.log('Map')
this.map = new google.maps.Map(this.mapElement.nativeElement, {
mapTypeId: google.maps.MapTypeId.SATELLITE
});
google.maps.event.trigger(this.map, 'resize')
console.log('Map Seconded')
}
}map.component.ts中的超文本标记语言
<div id="map-element" #mapElement></div>CSS用于设置global.css中地图元素的样式
#map-element {
display: block;
height: 400px;
}我有一种感觉,那就是问题可能出在哪里,在我找到解决方案后,我会重新生成它,AIzaSyB6RgF7vmUE0mjk_glikiuuSmpGpaNiA24
当我在Google Chrome上查看应用程序并尝试放大和缩小地图时,我收到此错误ERROR TypeError: Cannot read property 'zoom' of null
发布于 2019-09-13 05:54:30
就我个人而言,我需要在我的网站上使用谷歌地图的位置,所以我所做的就是将谷歌地图的位置嵌入到我的网站中,你可以点击“共享”,然后点击“嵌入地图”,然后你复制html代码并将其放入你的html代码中。
<a><iframe src="html code" class="map" width="250" height="200" frameborder="0"
style="border:0" allowfullscreen></iframe></a>https://stackoverflow.com/questions/57911368
复制相似问题