ApiKeyManager

Manages API keys for third-party tile providers.

Some map types (CYCLEMAP, TRANSPORT, TRANSPORT_DARK, TRACESTRACK_TOPO, CARTO_LIGHT, CARTO_DARK, CARTO_VOYAGER, STAMEN_TONER, STAMEN_WATERCOLOR) and the Stamen overlays in PredefinedTileProviders require API keys from tile providers. Keys can be configured in two ways:

1. AndroidManifest.xml (Recommended):

<application>
<meta-data
android:name="de.afarber.openmapview.THUNDERFOREST_API_KEY"
android:value="your_thunderforest_key_here"/>
<meta-data
android:name="de.afarber.openmapview.TRACESTRACK_API_KEY"
android:value="your_tracestrack_key_here"/>
<meta-data
android:name="de.afarber.openmapview.CARTO_API_KEY"
android:value="your_carto_key_here"/>
<meta-data
android:name="de.afarber.openmapview.STADIA_API_KEY"
android:value="your_stadia_key_here"/>
</application>

2. Programmatically (Runtime):

ApiKeyManager.setApiKey("thunderforest", "your_key_here")
ApiKeyManager.setApiKey("tracestrack", "your_key_here")
ApiKeyManager.setApiKey("carto", "your_key_here")
ApiKeyManager.setApiKey("stadia", "your_key_here")

API keys set programmatically override keys from the manifest.

Provider Names

  • "thunderforest" - For CYCLEMAP, TRANSPORT, and TRANSPORT_DARK map types

  • "tracestrack" - For TRACESTRACK_TOPO map type

  • "carto" - For CARTO_LIGHT, CARTO_DARK and CARTO_VOYAGER

  • "stadia" - For STAMEN_TONER, STAMEN_WATERCOLOR and the Stamen overlays

Obtaining API Keys

  • Thunderforest: https://www.thunderforest.com/pricing/ (Free: 150k tiles/month)

  • Tracestrack: https://www.tracestrack.com/en/signup (Free tier available)

  • CARTO: https://carto.com/basemaps/apikey (Free: 5M tiles/month non-commercial, 1M commercial)

  • Stadia Maps: https://client.stadiamaps.com/signup/ (Free tier for non-commercial use)

See also

Functions

Link copied to clipboard

Clears all programmatically-set API keys. Keys from AndroidManifest.xml are not affected.

Link copied to clipboard

Retrieves the API key for the given provider.

Link copied to clipboard

Checks if an API key is configured for the given provider.

Link copied to clipboard

Sets an API key programmatically for the given provider.