2

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

ccd
  • 119
  • 6
  • Do you enable MapKit in console? Do you check SHA-256 in console? – mohax Jan 07 '21 at 09:37
  • I double checked right now to be sure and yes I already put SHA-256 and enabled mapkit in the console. – ccd Jan 08 '21 at 00:38
  • Do you test on Huawei device? Maps only work on Huawei devices – mohax Jan 08 '21 at 09:39
  • I have a non huawei device but a workaround I did is to install hms core apk – ccd Jan 11 '21 at 03:45
  • 1
    Yes, as I can see in [docs](https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides-V5/android-sdk-version-change-history-0000001050156688-V5), latest version of MapKit doesn't require Huawei device, if you have latest HmsCore app and OS>=7 – mohax Jan 11 '21 at 08:40

2 Answers2

2

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

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
Zinna
  • 1,947
  • 2
  • 5
  • 20
  • I can display the maps now when calling inside the onViewCreated of the fragment. But I have a new problem when calling getMapAsync inside location callback – ccd Jan 11 '21 at 03:48
  • Glad your problem is resolved. What's your new problem? – Zinna Jan 11 '21 at 04:38
  • check my update on my post. It's when getMapAsync is called inside a LocationCallback – ccd Jan 11 '21 at 04:48
  • Sure, I'll take a look tomorrow when I have time. But fairly speaking, if your previous problem got resolved, you should give people the credit they deserve. – Zinna Jan 11 '21 at 05:42
  • i removed the update. I'll just post a new question since this is a different problem. Thanks for helping btw – ccd Jan 11 '21 at 06:41
1

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.
zhangxaochen
  • 32,744
  • 15
  • 77
  • 108