GriverMapCustomAPIKeyExtension

In the IAPMiniProgram SDK, if a mini program does not provide a Google API key or a Huawei API key, your app API key is used by default. To avoid charging your app unreasonable fees on Google or Huawei Maps service that is used in specific mini programs, you need to prevent the mini programs from using your app API key. Follow this topic to avoid using your app API key.

Procedures

To prevent the mini programs from using your app API key, follow these steps:

Step 1. Implement the GriverMapCustomAPIKeyExtension interface

Implement the GriverMapCustomAPIKeyExtension interface and write code in the required methods according to your business logic.

Code sample as follows:

copy
class CustomMapCustomAPIKeyExtensionImpl : GriverMapCustomAPIKeyExtension{
    override fun canUseGoogleAPIKey(appId: String?): Boolean {
        return false
    }

    override fun canUseHuaweiAPIKey(appId: String?): Boolean {
        return false;
    }
}

Step 2: Register the CustomMapCustomAPIKeyExtensionImpl class

Refer to the following sample code and call the registerExtension interface to register the CustomMapCustomAPIKeyExtensionImpl class after initializing the SDK.

copy
IAPConnect.init(application, initConfig, object : InitCallback() {
    fun onSuccess() {
        //ยทยทยท
        Griver.registerExtension(
            GriverExtensionManifest(
                GriverMapCustomAPIKeyExtension::class.java,
                CustomMapCustomAPIKeyExtensionImpl()
            )
        )
    }
})

Interface

GriverMapCustomAPIKeyExtension interface

The definition of the GriverMapCustomAPIKeyExtension interface is shown in the following codes:

copy
interface GriverMapCustomAPIKeyExtension : GriverExtension {
    fun canUseGoogleAPIKey(appId: String?): Boolean

    fun canUseHuaweiAPIKey(appId: String?): Boolean
}

Methods

Based on the definition above, this interface provides the following methods:

Method

Description

canUseGoogleAPIKey

Returns the result of whether the current appId can use Google Map API key.

If:

  • Return true : means the current appId can be used.
  • Return false: means the current appIdcannot be used.

canUseHuaweiAPIKey

Returns the result of whether the current appId can use Huawei Map API key.

If:

  • Return true : means the current appId can be used.
  • Return false: means the current appIdcannot be used.

canUseGoogleAPIKey method

Parameter

Data type

Required

Description

appId

String

No

The mini program appId.

canUseHuaweiAPIKey method

Parameter

Data type

Required

Description

appId

String

No

The mini program appId.