简体   繁体   English

HMS 地图工具包 - 在 getMapAsync() 调用后未调用 onMapReady()

[英]HMS Map toolkit - onMapReady() not called after getMapAsync() calling

I am working with HMS Maps, for this I follow their documentation.我正在使用 HMS Maps,为此我遵循他们的文档。
For this query I tried this link .对于这个查询,我尝试了这个链接 I added SHA-256 key and agconnect-services.json file too.我也添加了 SHA-256 密钥和 agconnect-services.json 文件。
The Steps which I did are:我做的步骤是:

dependency in app gradle: implementation 'com.huawei.hms:maps:6.0.0.301'应用程序 gradle 中的依赖项: implementation 'com.huawei.hms:maps:6.0.0.301'
in app gradle: apply plugin: 'com.huawei.agconnect'在应用程序gradle中: apply plugin: 'com.huawei.agconnect'
My root gradle is:我的根 gradle 是:

buildscript {
    repositories {
        maven { url 'http://developer.huawei.com/repo/' }
        google()
        jcenter()
        mavenCentral()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1'
        classpath 'com.google.gms:google-services:4.3.3'
        classpath 'com.huawei.agconnect:agcp:1.2.1.301'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven {url 'http://developer.huawei.com/repo/'}
        google()
        jcenter()
        mavenCentral()
        maven {
            url 'https://jitpack.io'
        }

        maven {
            url "https://github.com/QuickBlox/quickblox-android-sdk-releases/raw/master/"
        }

    }
}

I added SHA-256 key at AppGallery connect. 我在 AppGallery connect 添加了 SHA-256 密钥。
Enabled MapApi from AppGallery connect. 从 AppGallery 连接启用 MapApi。
Downloaded and added "agconnect-services.json" file in my project. 在我的项目中下载并添加了“agconnect-services.json”文件。

After resolving some thread related issues, I am able to produce logcat errors and it is saying that "Illegal FingerPrint". 解决了一些与线程相关的问题后,我能够产生 logcat 错误,并显示“非法指纹”。
I know, it is about some integration issues with the AppGallery but I am unable to get it that what I am missing, I am following all the steps. 我知道,这是关于 AppGallery 的一些集成问题,但我无法理解我缺少什么,我正在遵循所有步骤。
**Logcat is:** **Logcat 是:**
 2021-08-31 10:35:22.520 30490-30773/com.moody.poster E/HmsMapKit_AuthenticateClient_1074: Exception occur com.huawei.hms.maps.foundation.client.d: *1*0*2*:*I*L*G*L*F*N*E*P*I*T at com.huawei.hms.maps.foundation.client.d$dc(:89) at com.huawei.hms.maps.foundation.client.cd(:22556) at com.huawei.hms.maps.foundation.client.cc(:88) at com.huawei.hms.maps.maproute.client.auth.ed(:76) at com.huawei.hms.maps.maproute.client.auth.ea(Unknown Source:0) at com.huawei.hms.maps.maproute.client.auth.ba(Unknown Source:4) at com.huawei.hms.maps.foundation.client.c$ae(:492) at com.huawei.hms.maps.maproute.client.auth.ec(:1074) at com.huawei.hms.maps.maproute.cache.c$be(:298) at com.huawei.hms.maps.maproute.cache.c$b.call(:291) at eU.a(:42) at em.d(:12025) at fc$b.run(:96) at eq$c.run(:571) at fj.run(:66) at fj.call(:57) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:929) 2021-08-31 10:35:22.528 30490-30773/com.moody.poster E/HmsMapKit_ErrorTraceLogPusher_509: cache error trace log : ErrorTraceLogDTO{ scenario = ACCESS_SERVICE_ERROR', message='010002 : ILLEGAL_FINGERPRINT'} com.huawei.hms.maps.foundation.client.d: *1*0*2*:*I*L*G*L*F*N*E*P*I*T at com.huawei.hms.maps.foundation.client.d$dc(:89) at com.huawei.hms.maps.foundation.client.cd(:22556) at com.huawei.hms.maps.foundation.client.cc(:88) at com.huawei.hms.maps.maproute.client.auth.ed(:76) at com.huawei.hms.maps.maproute.client.auth.ea(Unknown Source:0) at com.huawei.hms.maps.maproute.client.auth.ba(Unknown Source:4) at com.huawei.hms.maps.foundation.client.c$ae(:492) at com.huawei.hms.maps.maproute.client.auth.ec(:1074) at com.huawei.hms.maps.maproute.cache.c$be(:298) at com.huawei.hms.maps.maproute.cache.c$b.call(:291) at eU.a(:42) at em.d(:12025) at fc$b.run(:96) at eq$c.run(:571) at fj.run(:66) at fj.call(:57) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:929) 2021-08-31 10:35:22.536 30490-30773/com.moody.poster E/HmsMapKit_AuthenticateCache_333: other err occur,errorCode : .010002 : ILLEGAL_FINGERPRINT 2021-08-31 10:35:22.775 30490-30490/com.moody.poster E/HmsMapKit_AccessTraceLogPusher_16: analyticsInstance is null 2021-08-31 10:35:22.778 30490-30490/com.moody.poster E/HmsMapKit_UserEventLogPusher_16: analyticsInstance is null

I had a similar problem once when I was implementing HMS Map.我在实施 HMS Map 时遇到过类似的问题。 In my case it was that I had the map on a fragment and was using the activity documentation.就我而言,我将地图放在片段上并使用活动文档。 To fix it I had to use the SupportMapFragment and everything worked correctly after that.为了修复它,我必须使用 SupportMapFragment,之后一切正常。

Update更新

In your following log:在您的以下日志中:

2021-08-31 10:35:22.528 30490-30773/com.moody.poster E/HmsMapKit_ErrorTraceLogPusher_509: cache error trace log : ErrorTraceLogDTO{ scenario = ACCESS_SERVICE_ERROR', message='010002 : ILLEGAL_FINGERPRINT'} 2021-08-31 10:35:22.528 30490-30773/com.moody.poster E/HmsMapKit_ErrorTraceLogPusher_509: 缓存错误跟踪日志:ErrorTraceLogDTO{ 场景 = ACCESS_SERVICE_ERROR', message='01000002' :

As Docs mentioned, The possible causes are as follows:正如文档所提到的,可能的原因如下:

  • The app ID in your project is different from that in AppGallery Connect.您项目中的应用 ID 与 AppGallery Connect 中的不同。

  • No signing certificate fingerprint is configured.未配置签名证书指纹。 You need to generate a signing certificate fingerprint and configure it in AppGallery Connect.您需要生成签名证书指纹并在 AppGallery Connect 中进行配置。

  • The AppGallery Connect configuration file of your app is not configured.您的应用程序的 AppGallery Connect 配置文件未配置。 You need to follow instructions in Adding the AppGallery Connect Configuration File of Your App to configure it.您需要按照添加应用程序的 AppGallery Connect 配置文件中的说明进行配置。

  • The API key is not transcoded using encode . API 密钥未使用encode 进行转码。

Also you can follow this Docs: Generating a Signing Certificate Fingerprint , see if there's a problem.您也可以按照此文档: 生成签名证书指纹,查看是否有问题。


The following Map kit codelab is for your reference.以下Map kit codelab供您参考。 You could follow this to see if its works.你可以按照这个来看看它是否有效。

1.Declare relevant permissions in blocks at the same level as the application block in the AndroidManifest.xml file. 1.在AndroidManifest.xml文件中在与应用程序块同级的块中声明相关权限。

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

2.Add MapView to the layout file. 2.在布局文件中添加MapView。 The file path is \\mapdemo\\app\\src\\main\\res\\layout\\activity_main.xml .文件路径是\\mapdemo\\app\\src\\main\\res\\layout\\activity_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 
    
    <com.huawei.hms.maps.MapView  
       xmlns:map="http://schemas.android.com/apk/res-auto" 
        android:id="@+id/mapView" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        map:cameraTargetLat="51" 
        map:cameraTargetLng="10" 
        map:cameraZoom="8.5" 
        map:mapType="normal" 
        map:uiCompass="true" 
        map:uiZoomControls="true" /> 
</LinearLayout>

3.Add the configuration for calling MapView to the activity file. 3.在activity文件中添加调用MapView的配置。 The file path is \\mapdemo\\app\\src\\main\\java\\com\\wz\\android\\mapdemo\\MainActivity.java .文件路径是\\mapdemo\\app\\src\\main\\java\\com\\wz\\android\\mapdemo\\MainActivity.java

package com.wz.android.mapdemo; 
 
import androidx.appcompat.app.AppCompatActivity; 
 
import android.os.Bundle; 
import android.util.Log; 
 
import com.huawei.hms.maps.HuaweiMap; 
import com.huawei.hms.maps.MapView; 
import com.huawei.hms.maps.OnMapReadyCallback; 
 
/** 
* Map activity entrance class. 
*/ 
public class MainActivity extends AppCompatActivity implements OnMapReadyCallback { 
 
    private static final String TAG = "MapViewDemoActivity"; 
    // Huawei map. 
    private HuaweiMap hMap; 
 
    private MapView mMapView; 
 
    private static final String MAPVIEW_BUNDLE_KEY = "MapViewBundleKey"; 
 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_main); 
        // Obtain a MapView instance. 
        mMapView = findViewById(R.id.mapView); 
        Bundle mapViewBundle = null; 
        if (savedInstanceState != null) { 
            mapViewBundle = savedInstanceState.getBundle(MAPVIEW_BUNDLE_KEY); 
        } 
 
        // Please replace Your API key with the API key in  
        // agconnect-services.json. 
        MapsInitializer.setApiKey("Your API key"); 
        mMapView.onCreate(mapViewBundle); 
        // Obtain a map instance. 
        mMapView.getMapAsync(this); 
    } 
 
    @Override 
    public void onMapReady(HuaweiMap map) { 
        // Obtain a map instance from callback. 
        Log.d(TAG, "onMapReady: "); 
        hMap = map; 
    } 
}

4.Add the lifecycle methods of MapView. 4.添加MapView的生命周期方法。 The file path is \\mapdemo\\app\\src\\main\\java\\com\\wz\\android\\mapdemo\\MainActivity.java .文件路径是\\mapdemo\\app\\src\\main\\java\\com\\wz\\android\\mapdemo\\MainActivity.java

@Override 
protected void onStart() { 
    super.onStart(); 
    mMapView.onStart(); 
} 
 
@Override 
protected void onStop() { 
    super.onStop(); 
    mMapView.onStop(); 
} 
 
@Override 
protected void onDestroy() { 
    super.onDestroy(); 
    mMapView.onDestroy(); 
} 
 
@Override 
protected void onPause() { 
    mMapView.onPause(); 
    super.onPause(); 
} 
 
@Override 
protected void onResume() { 
    super.onResume(); 
    mMapView.onResume(); 
}

5.Verify that required permissions have been assigned. 5. 验证是否已分配所需的权限。 The file path is \\mapdemo\\app\\src\\main\\java\\com\\wz\\android\\mapdemo\\MainActivity.java .文件路径是\\mapdemo\\app\\src\\main\\java\\com\\wz\\android\\mapdemo\\MainActivity.java

private static boolean hasPermissions(Context context, String... permissions) { 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && permissions != null) { 
        for (String permission : permissions) { 
            if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) { 
                return false; 
            } 
        } 
    } 
    return true; 
}

I am not sure that why it is happening, I talked to Huawei developers regarding this issue, I was doing this in a fragment but when I tried this in an activity, it works perfectly.我不确定为什么会发生这种情况,我就这个问题与华为开发人员进行了交谈,我在一个片段中进行了此操作,但是当我在活动中尝试此操作时,它运行良好。 Now I am doing it in a separate Activity.现在我在一个单独的活动中做它。 (I created that activity with the built in method of HMS toolkit.) (我使用 HMS 工具包的内置方法创建了该活动。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 华为 Map 套件 - 在 getMapAsync() 之后未调用 onMapReady() - Huawei Map Kit - onMapReady() not called after getMapAsync() ViewPager 中 Fragment 中的 MapView:在调用 getMapAsync() 后永远不会调用 onMapReady() - MapView in Fragment in ViewPager: onMapReady() is never called after calling getMapAsync() 华为地图套件 - 在 Xamarin.Android 中的 GetMapAsync() 之后未调用 OnMapReady() - Huawei Map Kit - OnMapReady() not called after GetMapAsync() in Xamarin.Android 地图:GMS 有效,HMS 无效; 未调用 onMapReady - Map: GMS works, HMS dont; onMapReady not called Xamarin表单映射自定义Android渲染器GetMapAsync不调用OnMapReady - Xamarin Forms Maps Custom Android Renderer GetMapAsync Not Calling OnMapReady HMS 地图工具包 - 渲染地图的问题 - HMS Map toolkit - issue rendering a Map 在片段中使用谷歌地图:从不调用 onMapReady - using google map in a fragment: onMapReady is never called onMapReady 未被调用 - onMapReady is not called Android SupportMapFragment.getMapAsync不调用OnMapReady - Android SupportMapFragment.getMapAsync Not Invoking OnMapReady 华为 Map 和 Location Kit - 在 LocationCallback 中调用 getMapAsync() 时出现错误 - Huawei Map and Location Kit - Bug when getMapAsync() is called inside LocationCallback
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM