ccd
ccd

Reputation: 129

Huawei Map Kit - onMapReady() not called after getMapAsync()

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()

Upvotes: 3

Views: 868

Answers (2)

Zinna
Zinna

Reputation: 2035

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

Upvotes: 2

zhangxaochen
zhangxaochen

Reputation: 34027

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.

Upvotes: 1

Related Questions