Skip to content

Bundling a Map

Bundle Maps at Build Time

Maps can be downloaded at build time and bundled into the resulting aab or apk file, which makes the maps available for immediate use when the user opens the app even if they are offline.

Bundle a single map

To bundle a single map specify the desired map id using the mapId key as so:

app/build.gradle
attractionsIo {
    mapId = "{map_id}"
}
app/build.gradle.kts
attractionsIo {
    setMapId("{map_id}")
}

This map id can be retrieved in your code by using BuildConfig.MAPLAYR_MAP_0 if buildConfig is enabled in your app's gradle file

app/build.gradle
android {
    buildFeatures {
        buildConfig = true
    }
}
app/build.gradle.kts
android {
    buildFeatures {
        buildConfig = true
    }
}

Bundle multiple maps

Multiple maps can be specified by using the mapIds key as so:

app/build.gradle
attractionsIo {
    mapIds = ["{map_id_1}", "{map_id_2}", ...]
}
app/build.gradle.kts
attractionsIo {
    setMapIds(listOf("{map_id_1}", "{map_id_2}", ...))
}

These map ids can be retrieved in your code by using BuildConfig.MAPLAYR_MAP_0, BuildConfig.MAPLAYR_MAP_1, ... , BuildConfig.MAPLAYR_MAP_N if buildConfig is enabled in your app's gradle file

app/build.gradle
android {
    buildFeatures {
        buildConfig = true
    }
}
app/build.gradle.kts
android {
    buildFeatures {
        buildConfig = true
    }
}

Bundle named map(s)

Map id(s) can be provided alongside a friendly name by using the maps key as so:

app/build.gradle
attractionsIo {
    maps = [
        "{my_first_map}": "{map_id_1}",
        "{my_second_map}": "{map_id_2}",
        ...
    ]
}
app/build.gradle.kts
attractionsIo {
    setMaps(
        mapOf(
            "{my_first_map}" to "{map_id_1}", 
            "{my_second_map}" to "{map_id_2}", 
            ...
        )
    )
}

These map id(s) can be retrieved in your code by using the friendly name(s); BuildConfig.MAPLAYR_MAP_MY_FIRST_MAP, BuildConfig.MAPLAYR_MAP_MY_SECOND_MAP if buildConfig is enabled in your app's gradle file

app/build.gradle
android {
    buildFeatures {
        buildConfig = true
    }
}
app/build.gradle.kts
android {
    buildFeatures {
        buildConfig = true
    }
}

Build variants, build types & product flavors

Any of the methodologies above for specifying map ids to be bundled into the app at build time can be nested in the build variants, build types or product flavors namespace to make them specific to that build.

app/build.gradle
attractionsIo {
    variants {
        variant1 {
            mapId = "{map_id}"
        }
        variant2 {
            mapId = "{map_id}"
        }
    }
    buildTypes {
        buildType1 {
            mapId = "{map_id}"
        }
        buildType2 {
            mapId = "{map_id}"
        }
    }
    productFlavors {
        productFlavor1 {
            mapId = "{map_id}"
        }
        productFlavor2 {
            mapId = "{map_id}"
        }
    }
}
app/build.gradle.kts
attractionsIo {
    variants {
        maybeCreate("variant1").apply {
            setMapId("{map_id}")
        }
        maybeCreate("variant2").apply {
            setMapId("{map_id}")
        }
    }
    buildTypes {
        maybeCreate("buildType1").apply {
            setMapId("{map_id}")
        }
        maybeCreate("buildType2").apply {
            setMapId("{map_id}")
        }
    }
    productFlavors {
        maybeCreate("productFlavor1").apply {
            setMapId("{map_id}")
        }
        maybeCreate("productFlavor2").apply {
            setMapId("{map_id}")
        }
    }
}

An example can be found here: app/build.gradle

Map Cache Configuration

The maps are cached for a default period of 24 hours but this can be modified. For example, a build system could have this set to 0 so that the latest map is downloaded for every build.

app/build.gradle
attractionsIo {
    cacheMapsForHours = 24
}
app/build.gradle.kts
attractionsIo {
    cacheMapsForHours = 24
}

An example can be found here: app/build.gradle