diff --git a/react-native-hms-map/android/src/main/java/com/huawei/hms/rn/map/HMSMapView.java b/react-native-hms-map/android/src/main/java/com/huawei/hms/rn/map/HMSMapView.java index 81b883d7..99d60a87 100644 --- a/react-native-hms-map/android/src/main/java/com/huawei/hms/rn/map/HMSMapView.java +++ b/react-native-hms-map/android/src/main/java/com/huawei/hms/rn/map/HMSMapView.java @@ -1411,13 +1411,18 @@ public String getName() { } @ReactMethod - public void initializer(final String apiKey, final String routePolicy, final Promise promise) { + public void initializer(final String apiKey, final String routePolicy, final String accessToken, final Promise promise) { if (routePolicy != null && !routePolicy.isEmpty()) { MapsInitializer.initialize(context, routePolicy); } else { MapsInitializer.initialize(context); } - MapsInitializer.setApiKey(apiKey); + if (accessToken != null && !accessToken.isEmpty()) { + MapsInitializer.setAccessToken(accessToken); + } + if (apiKey != null && !apiKey.isEmpty()) { + MapsInitializer.setApiKey(apiKey); + } promise.resolve(null); } diff --git a/react-native-hms-map/src/index.d.ts b/react-native-hms-map/src/index.d.ts index 057ddb3c..6e761586 100644 --- a/react-native-hms-map/src/index.d.ts +++ b/react-native-hms-map/src/index.d.ts @@ -1619,9 +1619,16 @@ declare module "@hmscore/react-native-hms-map" { /** * Initializes the Map SDK. You can set the data routing location. The options for routePolicy are CN (China), DE (Germany), SG (Singapore), and RU (Russia). - * Sets the access token of the Map SDK. - */ - initializer(apiKey: String, routePolicy: String): Promise; + * Sets the apiKey or accessToken of the Map SDK. + * apiKey does not need to be specified if the api_key field in the agconnect-services.json file already specifies an API key. + * If its set its takes precedence. + * If accessToken and apiKey set both, accessToken will be used for authentication + */ + initializer( + apiKey?: String, + routePolicy?: "CN" | "DE" | "SG" | "RU", + accessToken?: String + ): Promise; /** * Obtains all attributes of the Huawei map object