2

i'm trying to use the Huawei HMS map kit in my app, i'm new to maps overall (whether it be from google or huawei), i followed the tutorials in the documentation and in the code labs offered by huawei and put my code together but when i run the map activity nothing appears, all i get is a blank activity, i've written some log statements throughout my code and only one of them is logged which is put in the very top of the on create method. the app doesn't crash either.

here is my code, what could be wrong with it?


public class MapActivity extends AppCompatActivity implements OnMapReadyCallback {
 
    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_map);
 
        Log.i("TAG", "onCreate");
 
        //get mapview instance
        mMapView = findViewById(R.id.mapView);
 
        Bundle mapViewBundle = null;
        if (savedInstanceState != null) {
            mapViewBundle = savedInstanceState.getBundle(MAPVIEW_BUNDLE_KEY);
        }
 
        MapsInitializer.setApiKey(android.net.Uri.encode("my api key here"));
        mMapView.onCreate(mapViewBundle);
        //get map instance
        mMapView.getMapAsync(this);
    }
 
    @Override
    public void onMapReady(HuaweiMap map) {
        //get map instance in a callback method
        Log.d("TAG", "onMapReady: ");
        hMap = map;
    }
 
    @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();
    }
 
    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;
    }
}

outside of the code i've made sure of my huawei app gallery connect configuration, api key and all, as well as the needed dependencies in the gradle

and i checked my minSDK and made sure it was 19 too. still..nothing is working

please help me

Thanks

M.KH
  • 388
  • 1
  • 5
  • 20
  • Hope [this](https://medium.com/huawei-developers/how-to-integrate-hms-map-kit-add-marker-and-draw-circle-176df7f0de8f) helps. – Saurav Kumar Aug 09 '20 at 07:27
  • thank you, but i followed the steps in this as well and still have the same problem – M.KH Aug 09 '20 at 07:33
  • 1
    The supported device for Map Kit is HUAWEI mobile phone. What is your Android phone? – zhangxaochen Aug 10 '20 at 00:58
  • Wow..i was using a google pixel phone the whole time..so i just can't use this kit on phones other than huawei..what a waste of effort.. thank you very much ma'am! google maps here i come! – M.KH Aug 10 '20 at 01:32
  • yeah i came to that conclusion as well..i will look for a way which allows me to use both maps in the same application by detecting the device type and acting accordingly – M.KH Aug 10 '20 at 06:19
  • 1
    @M.KH The G+H solution can be used for integration. In this way, Google Maps can be used on Google mobile phones and Huawei Maps can be used on Huawei mobile phones. – zhangxaochen Aug 10 '20 at 07:15
  • do you have any resources that might help with that? – M.KH Aug 10 '20 at 07:51
  • 1
    @M.KH maybe this can help https://github.com/franalma/MapsWrapper to integrate both maps easily. Use the map API from this library to automatically select Google or Huawei maps and show accordingly. Check the example app for details. Hope it helps. – m0skit0 Aug 10 '20 at 09:17

1 Answers1

3

1. Why is this happening?

The Supported Devices for HUAWEI Map Kit is HUAWEI Mobile phone. If you use a Google phone, go to step 2.

2. How to?

If you

look for a way which allows me to use both maps in the same application by detecting the device type and acting accordingly,

you can use G+H Solution. Using the G+H approach, you are able to maintain one codebase and decide whether to use GMS or HMS based on the availability of either one.

First, check whether the GMS and HMS are available.

public boolean  isGMS(){
        return GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this) == com.google.android.gms.common.ConnectionResult.SUCCESS;
    }
public boolean  isHMS(){
        return HuaweiApiAvailability.getInstance().isHuaweiMobileServicesAvailable(this) == com.huawei.hms.api.ConnectionResult.SUCCESS;
}

Or please kindly refer to this: How to check Google Mobile Services enable in device or not?

Second, enter to different code branches and perform different map initialization tasks.

if(isGMS()) {
init Google map and functions
} else if(isHMS()) {
init Huawei map and functions
}

Hope it helps!

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108