1 Overview
This tutorial helps you migrate the Google Map SDK for Android to the HMS Core Map SDK for Android in your Android app. It starts with basic environment settings, and covers some basic use cases, such as creating a map and adding a marker. At the bottom of the page is a summary in which we provide links to an automated tool that helps you finish the migration.
2 Preparations
Before integrating HMS Core Map Kit, complete the following preparations:
For details, please refer to Preparations for Integrating HUAWEI HMS Core.
3 Creating a Map
This section describes how to create a map using Google Map SDK and HMS Core Map Kit.
3.1 Google Map SDK
1. Add build dependencies to the build.gradle file of your app.
2. Add a fragment to the activity layout file.
3. Add a Google Android API key in the application section in the manifest.xml file.
3.2 Map Kit
1. Add build dependencies to the build.gradle file of your app.
2. Add a fragment to the activity layout file.
4 Adding a Marker
This section describes how to add a marker using Google Map SDK and HMS Core Map Kit.
4.1 Google Map SDK
1. Define a GoogleMap object and a MapFragment object.
2. Implement the OnMapReadyCallback API and override the onMapReady method.
3. Load MapFragment in the onCreate method of the activity and call getMapAsync().
4.2 Map Kit
1. Define a HuaweiMap object and a MapFragment object.
2. Implement the OnMapReadyCallback API and override the onMapReady method.
3. Load MapFragment in the onCreate method of the activity and call getMapAsync().
5 Summary
This tutorial has covered the differences between the Google Map SDK and HMS Core Map Kit. HMS ToolKit, an automated tool, is also provided to help you migrate from the Google Map SDK to HMS Core Map Kit or add HMS Core Map Kit to your app efficiently. For details, visit the following links:
HMS ToolKit - Overview
Map Kit Manual Conversion Guide
This tutorial helps you migrate the Google Map SDK for Android to the HMS Core Map SDK for Android in your Android app. It starts with basic environment settings, and covers some basic use cases, such as creating a map and adding a marker. At the bottom of the page is a summary in which we provide links to an automated tool that helps you finish the migration.
2 Preparations
Before integrating HMS Core Map Kit, complete the following preparations:
- Create an app in AppGallery Connect.
- Create an Android Studio project.
- Generate a signing certificate and a signing certificate fingerprint.
- Configure the signing certificate fingerprint in AppGallery Connect.
- Integrate the HMS SDK.
- Configure a project signature.
For details, please refer to Preparations for Integrating HUAWEI HMS Core.
3 Creating a Map
This section describes how to create a map using Google Map SDK and HMS Core Map Kit.
3.1 Google Map SDK
1. Add build dependencies to the build.gradle file of your app.
Code:
implementation 'com.google.android.gms:play-services-maps:15.0.0'
Code:
<fragment
android:id="@+id/mapFragment"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Code:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_GOOGLE_KEY_GOES_HERE"/>
1. Add build dependencies to the build.gradle file of your app.
Code:
implementation 'com.huawei.hms:maps:4.0.1.301'
Code:
<fragment
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/mapfragment_mapfragmentdemo"
class="com.huawei.hms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:cameraTargetLat="48"
map:cameraTargetLng="118"/>
This section describes how to add a marker using Google Map SDK and HMS Core Map Kit.
4.1 Google Map SDK
1. Define a GoogleMap object and a MapFragment object.
Code:
private GoogleMap gMap;
private MapFragment mapFragment;
Code:
@Override
public void onMapReady(GoogleMap googleMap) {
gMap = googleMap;
LatLng amsterdam = new LatLng(52.37, 4.90);
gMap.addMarker(new MarkerOptions().position(amsterdam).title("Amsterdam"));
gMap.animateCamera(CameraUpdateFactory.newLatLngZoom(amsterdam, 8));
}
Code:
mapFragment = (MapFragment)getFragmentManager().findFragmentById(R.id.mapFragment);
mapFragment.getMapAsync(this);
1. Define a HuaweiMap object and a MapFragment object.
Code:
private HuaweiMap hMap;
private MapFragment mMapFragment;
Code:
@Override
public void onMapReady(HuaweiMap map) {
// after call getMapAsync method ,we can get HuaweiMap instance in this callback method
hMap = map;
hMap.addMarker(new MarkerOptions().position(new LatLng(31.2304, 121.4737)).icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher_background)));
hMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(31.2304, 121.4737), 10));
}
Code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map_fragment_demo);
mMapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.mapfragment_mapfragmentdemo);
mMapFragment.getMapAsync(this);
}
This tutorial has covered the differences between the Google Map SDK and HMS Core Map Kit. HMS ToolKit, an automated tool, is also provided to help you migrate from the Google Map SDK to HMS Core Map Kit or add HMS Core Map Kit to your app efficiently. For details, visit the following links:
HMS ToolKit - Overview
Map Kit Manual Conversion Guide