android - Ionic Angular Google maps javascript API 适用于浏览器和 Ios,但不适用于 Android
问题描述
我很难弄清楚为什么我的代码可以在 web 和 ios 上轻松运行,但在 Android 上显示一个空白 div 而没有任何错误。我正在使用 Ionic Angular,并且我已经对 API 密钥进行了三次检查。我的猜测是它与 shadow-root 有关,但我每次尝试修复它都失败了。对于我可能缺少的任何见解,我将非常感激,在此先感谢!
HTML:
<ion-content fullscreen class="mapContent">
<ion-grid class="container mapContent">
<ion-row class="mapContent">
<div #map id="map" class="map"></div>
</ion-row>
</ion-grid>
</ion-content>
TS:
@ViewChild('map') mapElement: ElementRef;
map: any;
constructor(
private geolocation: Geolocation,
) {}
ionViewDidEnter() {
this.loadGoogleMaps();
}
loadGoogleMaps(){
window['mapInit'] = () => {
this.initMap();
}
let script = document.createElement("script");
script.id = "googleMaps";
script.src = 'http://maps.google.com/maps/api/js?key=' + this.apiKey + '&callback=mapInit';
document.body.appendChild(script);
}
initMap(){
this.mapInitialised = true;
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);
this.map.addListener("click", (e) => {
this.placeMarker(e.latLng, this.map);
});
});
}
CSS:
ion-content.mapContent {
--background: transparent !important;
}
ion-grid.mapContent {
--background: transparent !important;
}
ion-row.mapContent {
--background: transparent !important;
}
.map {
margin: 10px 5px 20px;
border-radius: 20px;
width: 100%;
height: 200px;
}
解决方案
推荐阅读
- java - JavaFX 导出和 VM 参数
- azure - 如何将 Azure 资源组从一个 azure 帐户移动到另一个 azure 帐户?
- ruby - RSpec“允许”静默终止“它”块
- javascript - Vue,将多个参数/参数传递给函数
- javascript - 按两个项目过滤 react-instantsearch
- xcode - IBUIColor.m 中的断言失败 - Xamarin.iOS
- java - JPQL 查询从一对一关系中选择实体,其中它的相对具有匹配特定条件的字段
- javascript - 删除类不会停止 IE11 中的关键帧动画
- python - 从现有行生成新的 Dataframe 列
- django - 我想问一下Django代码块中的错误