2
votes

I'm trying to create a huawei variant of a locator feature of a project that uses google maps. But my problem is that onMapReady() callback does not trigger at all after getMapAsync()

This is how i call getMapAsync:

     val mapFragment = childFragmentManager.findFragmentById(R.id.fragment_huawei_map_container) as SupportMapFragment
     mapFragment.getMapAsync(this@SampleMapsFragment)

This works fine when using google maps depedencies as onMapReady() is getting called.

But when using huawei map dependencies, onMapReady callback does not trigger at all after getMapAsync()

2
Do you enable MapKit in console? Do you check SHA-256 in console?mohax
I double checked right now to be sure and yes I already put SHA-256 and enabled mapkit in the console.ccd
Do you test on Huawei device? Maps only work on Huawei devicesmohax
I have a non huawei device but a workaround I did is to install hms core apkccd
Yes, as I can see in docs, latest version of MapKit doesn't require Huawei device, if you have latest HmsCore app and OS>=7mohax

2 Answers

1
votes

The onMapReady method needs to be reloaded. The following describes how to create a map instance using SupportMapFragment. For more details, see docs.

  1. Add a Fragment object in the layout file (for example, activity_main.xml), and set map attributes in the file
<fragment xmlns:android="http://schemas.android.com/apk/res/android"        
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:id="@+id/mapfragment_mapfragmentdemo"
    class="com.huawei.hms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    map:cameraTargetLat="48.893478"
    map:cameraTargetLng="2.334595"
    map:cameraZoom="10" />
  1. To use a map in your app, implement the OnMapReadyCallback API in the MainActivity.java file. The sample code is as follows:
public class SupportMapDemoActivity extends AppCompatActivity implements OnMapReadyCallback {
    ...
}
  1. In the MainActivity.java file, load SupportMapFragment in the onCreate() method and call getMapAsync() to register the callback. The sample code is as follows:
private SupportMapFragment mSupportMapFragment; 
mSupportMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapfragment_mapfragmentdemo);
mSupportMapFragment.getMapAsync(this);
  1. Call the onMapReady callback to obtain the HuaweiMap object. The sample code is as follows:
public void onMapReady(HuaweiMap huaweiMap) {
    Log.d(TAG, "onMapReady: ");     
    hMap = huaweiMap;
}
  1. Run your project and then install your app to view the map in your app.
1
votes

Since you are using the Huawei's map kit to do these please check the following: You have generated a sha256 key and integrated HMS core, you can use this link to find out how.

If you have done all the above, make sure that agconnect-services.json is in the right place. Then, check if in your manifest you have:
enter image description here

A final thing to check is that if you have done enter image description here

I hope one of these will help as I was able to get onMapReady to trigger:

enter image description here