I'm Trying to use HMS Map Kit in my project, the map is loaded but its never rendering
Gradle:app
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.huawei.agconnect:agconnect-core:1.4.1.300'
implementation 'com.huawei.hms:maps:5.0.2.300'
}
apply plugin: 'com.huawei.agconnect'
Build:Gradle :
repositories {
google()
jcenter()
maven { url 'http://developer.huawei.com/repo/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {url 'http://developer.huawei.com/repo/'}
}
Manifest :
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name=
"com.huawei.appmarket.service.commondata.permission.GET_COMMON_DATA"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
Activity :
public class MainActivity extends AppCompatActivity implements OnMapReadyCallback {
private static final String MAP_VIEW_BUNDLE_KEY = "MapViewBundleKey";
private HuaweiMap hMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Bundle mapViewBundle = null;
if (savedInstanceState != null) {
mapViewBundle = savedInstanceState.getBundle(MAP_VIEW_BUNDLE_KEY);
}
MapView mapView = findViewById(R.id.mapView);
mapView.onCreate(mapViewBundle);
mapView.getMapAsync(this);
}
@Override
public void onMapReady(HuaweiMap huaweiMap) {
hMap = huaweiMap;
hMap.setMyLocationEnabled(true);
hMap.getUiSettings().setMyLocationButtonEnabled(true);
hMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(48.864716, 2.349014), 10));
hMap.setOnMapLoadedCallback(new HuaweiMap.OnMapLoadedCallback() {
@Override
public void onMapLoaded() {
Log.i("==========>", "[Map] Loaded.");
}
});
}
}
Please not : that i downloaded and added the agconnect-services.json file to the project and added the SHA-256 certificate fingerprint to the App informations also, but i don't know what Im missing ?
There may be different causes of this problem. Please check as follows:
(1) Set the API key in the entrance class of your project.
// In the entrance class (inherited from android.app.Application) of the app,
// call the setApiKey method in the overridden onCreate() method.
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
// Set the API key.
MapsInitializer.setApiKey("Your API Key");
}
}
(2) Set the API key in Fragment or MapView.
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "onCreate: ");
super.onCreate(savedInstanceState);
// Set the API key before calling setContentView.
MapsInitializer.setApiKey("Your API Key");
setContentView(R.layout.basic_demo);