我已按照本指南將華為 HMS 地圖添加到我的 IONIC 電容器運行時應用程式中。 https://github.com/HMS-Core/hms-cordova-plugin/tree/master/cordova-plugin-hms-map/example/ionic
這個應用有 google-services.json 和 huawei agconnect-services.json。
在專案 build.gradle 我正在使用
[...]
classpath 'com.huawei.agconnect:agcp:1.5.2.300'
電容器.build.gradle
dependencies {
[...]
implementation "com.huawei.hms:base:5.2.0.300"
implementation "com.huawei.hms:maps:6.0.1.304"
}
這是 npm 庫
npm install @hmscore/cordova-plugin-hms-map@latest
npm install @ionic-native/core @hmscore/ionic-native-hms-map@latest
在華為開發者控制臺中設定合適的sha2指紋。應用程式構建.gradle。
signingConfigs {
config {
storeFile file('huawei.jks')
storePassword '*****'
keyAlias 'mapshowcase'
keyPassword '*****'
}
}
dependencies {
[...]
implementation 'com.huawei.agconnect:agconnect-core:1.5.2.300'
}
async initMap() {
const mapOptions = {
mapType: MapType.MAP_TYPE_TERRAIN,
cameraPosition: {
target: {lat: 40.7587658, lng: 30.3146964},
zoom: 2
}
};
this.hmsMap.requestPermission();
this.map = await this.hmsMap.getMap('map', mapOptions, {marginTop: 50});
this.addListener();
this.map.setMyLocationEnabled(true);
this.map.getUiSettings().setMyLocationButtonEnabled(true);
this.map.getProjection().getVisibleRegion().then(vr => console.log(JSON.stringify(vr)));
this.map.getProjection().toScreenLocation({lat: 12, lng: 43}).then(point => console.log(JSON.stringify(point)));
this.map.getProjection().fromScreenLocation({x: 300, y: 600}).then(latLng => console.log(JSON.stringify(latLng)));
}
在華為 Harmony OS 手機上測驗,但出現此錯誤。
E/HmsMapKit_ErrorTraceLogPusher_4: cache error trace log : ErrorTraceLogDTO{ scenario = ACCESS_SERVICE_ERROR', message='5 : Unknown Code - 5'}
com.huawei.hms.maps.foundation.client.mac: * * *n*n*w* *o*e*-*5
at com.huawei.hms.maps.foundation.client.mac$maa.b(Unknown Source:25)
at com.huawei.hms.maps.foundation.client.mab.a(Unknown Source:20)
at com.huawei.hms.maps.foundation.client.mab.c(Unknown Source:80)
at com.huawei.hms.maps.foundation.client.mab.a(Unknown Source:88)
at com.huawei.hms.maps.provider.client.tile.maa.a(Unknown Source:1)
at com.huawei.hms.maps.provider.client.tile.maa.lambda$gI3f4RyIuh0G4Qoia5V0XosFnEE(Unknown Source:0)
at com.huawei.hms.maps.provider.client.tile.-$$Lambda$maa$gI3f4RyIuh0G4Qoia5V0XosFnEE.call(Unknown Source:6)
at com.huawei.hms.maps.foundation.client.mab$maa.a(Unknown Source:3)
at com.huawei.hms.maps.provider.client.tile.maa.c(Unknown Source:23)
at com.huawei.hms.maps.provider.client.tile.maa.a(Unknown Source:4)
at com.huawei.hms.maps.provider.cache.mag.a(Unknown Source:63)
at com.huawei.hms.maps.provider.cache.mag$mac.startUrlRequest(Unknown Source:2)
at com.huawei.map.MapController.startUrlRequest(Unknown Source:28)
到目前為止,我還沒有在互聯網上找到有關此類錯誤的任何解決方案或詳細資訊。任何幫助表示贊賞。
更新 1 看起來地圖構造正確:
I/Capacitor/Console: File: http://localhost/ - Line 6588 - Msg: Huawei map constructed with the div id map :: and the props 1
但是目標地圖 div 保持空白,當我點擊它時,我能夠看到正在記錄的點擊。
addListener() {
const log = document.getElementById('log');
this.map.on(MapEvent.ON_MAP_CLICK, (latLng) => {
log.innerHTML = '<br>' 'Map_Click:' latLng.lat '<-->' latLng.lng log.innerHTML;
});
this.map.on(MapEvent.ON_MAP_LONG_CLICK, (latLng) => {
log.innerHTML = '<br>' 'Map_Long_Click:' latLng.lat '<-->' latLng.lng log.innerHTML;
});
}
更新 2 問題在于地圖 div 的父 div 的透明度。該插件不會在地圖初始化時自動將背景設定為對其所有父節點透明。
uj5u.com熱心網友回復:
提供的日志是不夠的。最好在此處創建票證:https ://developer.huawei.com/consumer/en/support/feedback/#/ 并將所有日志檔案放入票證中。
或者您可以搜索“HmsMap”并在此處分享搜索結果。
uj5u.com熱心網友回復:
通過在必須顯示地圖時設定所有地圖 div 的父離子內容節點的 css 值并在地圖頁面被破壞時將其洗掉來解決該問題。
全域.scss
--ion-background-color: var(--map-background, white);
.background-transparent {
--map-background: transparent !important;
}
地圖.page.ts
ionViewDidEnter(){
document.body.classList.toggle('background-transparent', true);
}
ionViewWillLeave(){
document.body.classList.toggle('background-transparent', false);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/462435.html
上一篇:找不到com.google.android.gms:play-services-base:20.4.0。安卓-科爾多瓦
