【问题标题】:HMS Map toolkit - onMapReady() not called after getMapAsync() callingHMS 地图工具包 - 调用 getMapAsync() 后未调用 onMapReady()
【发布时间】:2021-08-27 12:43:49
【问题描述】:

我正在使用 HMS 地图,为此我遵循他们的文档。
对于这个查询,我尝试了这个link。我也添加了 SHA-256 密钥和 agconnect-services.json 文件。
我所做的步骤是:

app gradle 中的依赖:implementation 'com.huawei.hms:maps:6.0.0.301'
在应用程序中:apply plugin: 'com.huawei.agconnect'
我的根 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/"
        }

    }
}

我在 AppGallery 连接处添加了 SHA-256 密钥。
从 AppGallery 连接启用 MapApi。
在我的项目中下载并添加了“agconnect-services.json”文件。

在解决了一些与线程相关的问题后,我能够产生 logcat 错误,并且说“非法指纹”。
我知道,这与 AppGallery 的一些集成问题有关,但我无法理解我所缺少的,我正在遵循所有步骤。
**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$d.c(:89)
        at com.huawei.hms.maps.foundation.client.c.d(:22556)
        at com.huawei.hms.maps.foundation.client.c.c(:88)
        at com.huawei.hms.maps.maproute.client.auth.e.d(:76)
        at com.huawei.hms.maps.maproute.client.auth.e.a(Unknown Source:0)
        at com.huawei.hms.maps.maproute.client.auth.b.a(Unknown Source:4)
        at com.huawei.hms.maps.foundation.client.c$a.e(:492)
        at com.huawei.hms.maps.maproute.client.auth.e.c(:1074)
        at com.huawei.hms.maps.maproute.cache.c$b.e(: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$d.c(:89)
        at com.huawei.hms.maps.foundation.client.c.d(:22556)
        at com.huawei.hms.maps.foundation.client.c.c(:88)
        at com.huawei.hms.maps.maproute.client.auth.e.d(:76)
        at com.huawei.hms.maps.maproute.client.auth.e.a(Unknown Source:0)
        at com.huawei.hms.maps.maproute.client.auth.b.a(Unknown Source:4)
        at com.huawei.hms.maps.foundation.client.c$a.e(:492)
        at com.huawei.hms.maps.maproute.client.auth.e.c(:1074)
        at com.huawei.hms.maps.maproute.cache.c$b.e(: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


【问题讨论】:

  • hi@Faizan,请问您的地图显示了吗?你能把地图显示类的代码贴出来吗?
  • 不,我的地图没有加载,调用“getMapAsync(this)”函数后,无法获取“onMapReady(HuaweiMap huaweiMap)”回调函数。
  • hi@Faizan,您能否提供地图套件的错误日志以供我们检查此问题?
  • 有一些线程问题,解决后我能够产生 logcat 错误。我的问题是与 AppGallery 的一些集成(非法指纹)我正在更新我的问题,请查看它。我会非常感谢你。

标签: android maps huawei-mobile-services huawei-developers huawei-map-kit


【解决方案1】:

我在实现 HMS Map 时遇到过类似的问题。在我的情况下,我将地图放在片段上并使用活动文档。要修复它,我必须使用 SupportMapFragment,之后一切正常。

【讨论】:

  • 我已经在使用 SupportMapFragment,感谢您的回答。
【解决方案2】:

更新

在您的以下日志中:

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

正如Docs所说,可能的原因如下:

  • 您的项目中的应用ID与AppGallery Connect中的不同。

  • 未配置签名证书指纹。您需要生成签名证书指纹并在AppGallery Connect中进行配置。

  • 您的应用的AppGallery Connect配置文件未配置。您需要按照Adding the AppGallery Connect Configuration File of Your App 中的说明进行配置。

  • API 密钥未使用 encode 进行转码。

你也可以关注这个Docs:Generating a Signing Certificate Fingerprint,看看有没有问题。


以下Map kit codelab供您参考。你可以按照这个来看看它是否有效。

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.将 MapView 添加到布局文件中。文件路径为\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.在activity文件中添加调用MapView的配置。文件路径为\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.增加MapView的生命周期方法。文件路径为\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.验证是否已分配所需的权限。文件路径为\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; 
}

【讨论】:

  • 感谢您的回答,我用 logcat 错误更新了我的问题。请看一下。这是关于一些整合。但我无法追踪它。
  • hi@Faizan,我更新了上面的答案,请参考。
  • 我无法解决这个问题。我在一个片段中尝试它,它给了我“ILLEGAL_FINGERPRINT”,这意味着应用程序与 AppGallery 的配置不正确。现在我在一个活动中尝试它,它工作正常。如果存在“ILLEGAL_FINGERPRINT”问题,那么它也应该影响 Activity。但是现在,有了 Activity,它工作正常,不知道是什么问题。顺便说一句,感谢您的支持。
  • 很高兴听到问题已得到解决。如果您需要任何进一步的帮助,请随时与我联系。 ?
  • 是的,但我有一个问题,为什么它不能在片段上工作,为什么它说“ILLEGAL_FINGERPRINT”?
【解决方案3】:

我不确定为什么会这样,我就这个问题与华为开发人员进行了交谈,我在片段中执行此操作,但当我在活动中尝试此操作时,它完美运行。现在我在一个单独的活动中做这件事。 (我使用 HMS 工具包的内置方法创建了该活动。)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-06
    • 2016-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多