Getting Started

Getting Started

Getting started with MapsGL is quick and easy and requires that you have an active Xweather Flex subscription (opens in a new tab). Also, check out our demo project (opens in a new tab) for a more in-depth example of integrating the MapsGL SDK with your app.

Supported Mapping Libraries

MapsGL SDK for Android currently supports integration with the following third-party mapping libraries:

Library + VersionController
Mapbox GL (opens in a new tab), version v11.0.0+MapboxMapController

Installing

Our MapsGL SDK for Android is distributed as an AAR package that can be used with Android Studio. You can install the MapsGL SDK by adding the AAR package to your project's dependencies.

Follow the series of steps outlined below to get started using the Xweather MapsGL SDK for Android:

Create an Xweather account

Sign up for an Xweather Flex subscription (opens in a new tab) and setup your access keys as described in our Xweather Weather API's getting started guide (opens in a new tab). We offer a free developer account (opens in a new tab) for you to give our weather API a test drive.

Include the MapsGL SDK packages for Android

Open your project's settings.gradle file and add a new maven {...} definition inside the dependencyResolutionManagement.repositories block and include the MapsGL repository:

settings.gradle
pluginManagement {
    repositories {
        google()
        mavenCentral()
    }
}
dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()

        // MapsGL Maven repository
        maven {
            url 'https://maven.pkg.github.com/vaisala-xweather/mapsgl-android-sdk'
        }
    }
}

Next, add the MapsGL SDK dependency to your project's app-level build.gradle Gradle configuration file:

build.gradle

dependencies {
    implementation "com.xweather:mapsglmaps:v1.0.0-beta.2"
}

Set up MapsGL with your Xweather account

Set up your Xweather account access keys (opens in a new tab) for the SDK and create a map controller instance that corresponds to the mapping library you are using.

Once you've completed the above installation steps, you can use the following Kotlin code snippet to get started quickly using Mapbox in your project. Make sure you also have Mapbox SDK set up in your project according to their Getting Started guide (opens in a new tab).

package com.example.basicmapsglproject
 
import android.os.Bundle
import android.view.ViewTreeObserver
import androidx.appcompat.app.AppCompatActivity
import com.example.basicmapsglproject.databinding.ActivityMainBinding
import com.mapbox.maps.MapLoadedCallback
import com.mapbox.maps.Style
import com.mapbox.maps.extension.style.layers.properties.generated.ProjectionName
import com.mapbox.maps.extension.style.projection.generated.projection
import com.mapbox.maps.extension.style.projection.generated.setProjection
import com.xweather.mapsglmaps.config.weather.account.XweatherAccount
import com.xweather.mapsglmaps.map.mapbox.MapboxMapController
 
class MainActivity : AppCompatActivity() {
 
    private lateinit var mapController: MapboxMapController
 
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
 
        // Set up your Xweather account and access keys for the SDK
        var xweatherAccount = XweatherAccount(
            getString(R.string.xweather_client_id),
            getString(R.string.xweather_client_secret)
        )
 
        var binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        var mapView = binding.mapView
 
        // Add functionality and data to your map once the controller's `load` event has been triggered.
        val mapLoadedCallback = MapLoadedCallback {
            // Do stuff with the MapsGL map controller, like add weather layers
            mapController.addWeatherLayer("temperatures")
        }
 
        binding.mapView.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
            override fun onGlobalLayout() {
                binding.mapView.viewTreeObserver.removeOnGlobalLayoutListener(this)
 
                // Create a map controller that corresponds to the selected mapping library, passing in your `mapView` and `xweatherAccount` instances.
                mapController = MapboxMapController(mapView, baseContext, xweatherAccount,this@MainActivity)
 
                with(mapController) {
                    mapboxMap.loadStyle(Style.MAPBOX_STREETS)
                    mapboxMap.setProjection(projection(ProjectionName.MERCATOR))
                    mapboxMap.subscribeMapLoaded(mapLoadedCallback)
                }
            }
        })
    }
}