By now, you probably know all about Huawei’s infamous U.S. trade ban. With Huawei being blacklisted by the U.S. Department of Commerce, all Huawei devices since then can no longer shipped with Google Mobile Services (GMS) by default.
Given the circumstances, Huawei's current solution is to create its own platform as a replacement - Huawei Mobiles Services (HMS). Huawei Mobile Services has been around for years, but Huawei relaunched and expanded the platform following the U.S. trade ban that deprived it of GMS.
One feature of GMS that being used in most of the apps I developed so far is Google Maps and with about one-fourth of my user base currently using Huawei devices, it is clear to me that supporting HMS is essential.
However, supporting both GMS and HMS is quite cumbersome and requires you to maintains separate codebase for each platform. Take a look at one of the examples in the following snippets:
import com.huawei.hms.maps.CameraUpdateFactory
import com.huawei.hms.maps.model.LatLng
import com.huawei.hms.maps.model.MarkerOptions
mapView.getMapAsync { map ->
val location = LatLng(13.7650594, 100.5383354)
val marker = MarkerOptions().position(location)
map.addMarker(marker)
map.animateCaemra(CameraUpdateFactory.newLatLngZoom(location, 16f))
}
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.MarkerOptions
mapView.getMapAsync { map ->
val location = LatLng(13.7650594, 100.5383354)
val marker = MarkerOptions().position(location)
map.addMarker(marker)
map.animateCaemra(CameraUpdateFactory.newLatLngZoom(location, 16f))
}
You may notice that both codes are the same, except import statements. It may look simple at first, but the problem is you cannot share logic between these two APIs. That's not good.
So, my solution to this problem is to implement a wrapper library that encapsulate both APIs and decide which API to be used at runtime. It is now available on GitHub.
SupasinTatiyanupanwong / map-kit-android
Encapsulates Google Maps SDK for Android and HUAWEI Map Kit.
Map Kit
Abstraction wrapper that encapsulates Maps APIs of supported platforms for Android, allowing access to multiple Maps APIs while maintaining your application single codebase.
Map Kit is currently providing support for Google Maps and Huawei Maps.
Usage
This project contains 3 artifacts; maps-core
, maps-google
, and maps-huawei
.
maps-core
artifact provides abstraction interface to interact with Maps APIs.
maps-google
artifact provides Google Maps integration.
maps-huawei
artifact provides Huawei Maps integration.
Migration from existing Maps APIs
Google Name | Huawei Name | Map Kit Name |
---|---|---|
com.google.android.gms.maps.* |
com.huawei.hms.maps.* |
me.tatiyanupanwong.supasin.android.libraries.kits.maps.* |
GoogleMap |
HuaweiMap |
MapClient |
new LatLng() |
new LatLng() |
MapKit.newLatLng() |
new *Options() |
new *Options() |
MapKit.new*Options() |
*.builder() |
*.builder() |
MapKit.new*Builder() |
*Factory.*() |
*Factory.*() |
MapKit.get*Factory().*() |
Tile.NO_TILE |
Tile.NO_TILE |
MapKit.noTile() |
Limitations
- Models are currently not
Parcelable
. -
*MapOptions
is currently not supported. - Google's
StreetView
is currently not supported.
Additional documentation
Download
Add the following to your…
I hope you find this useful. Please check it out and thanks for reading!
P.S. I do have other library projects like this in my pipeline, so I may publish them at some point.
Top comments (0)