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).

Supported Mapping Libraries

MapsGL SDK for Apple Platforms current supports integration with the following third-party mapping libraries:

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

Installing

Follow the series of steps outlined below for your desired method to get started using the Xweather MapsGL SDK for Apple Platforms:

Install using Swift Package Manager

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.

Added Mapbox package or frameworks

Add Mapbox (v11.0.0 or newer) to your project/workspace and app target according to the Mapbox Maps SDK for iOS Installation (opens in a new tab) instructions, using any dependency method (Swift Package Manager, CocoaPods, or Direct download).

Add the MapsGL SPM Package

In your iOS app Xcode project or workspace:

  1. Run File menu ❯ Add Package Dependencies…
  2. In the top-right “Search or Enter Package URL” field, type https://github.com/vaisala-xweather/mapsgl-apple-sdk.
  3. Click Add Package in the bottom-right.
  4. In the “Choose Package Products for mapsgl-apple-sdk” dialog, ensure your app target is selected under “Add to Target”, and click Add Package.

The MapsGL package will be added to your project, along with MapboxMaps and related packages (under Package Dependencies in the Project Navigator on the left).

A MapsGL static library will be added to your app target's “Frameworks, Libraries, and Embedded Content” section, and associated dynamic binary xcframeworks for MapsGL and Mapbox will be automatically added to your built app's frameworks by Xcode's build system.

Set up a map view

Set up an interactive map instance using a supported third-party mapping library if your application does not have one already.

Set up MapsGL with your map

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 (see below).

You can use the following Swift code snippet to get started quickly using MapsGL with a Mapbox in a UIViewController. Be sure to update the code to use your Xweather account access keys and Mapbox public access token instead.

import MapboxMaps
import MapsGLMaps
import MapsGLMapbox
import Combine
 
let xweatherClientID = "CLIENT_ID"
let xweatherClientSecret = "CLIENT_SECRET"
let mapboxAccessToken = "MAPBOX_PUBLIC_ACCESS_TOKEN"
var loadSubscription: AnyCancellable?
 
// …
 
override func viewDidLoad()
{
    super.viewDidLoad()
    // Set up the ``MapboxMaps.MapView``.
    MapboxOptions.accessToken = mapboxAccessToken
    let mapView = MapboxMaps.MapView(
        frame: self.view.bounds,
        mapInitOptions: .init(cameraOptions: .init(zoom: 2))
    )
    try! mapView.mapboxMap.setProjection(.init(name: .mercator)) // Set 2D map projection
    mapView.autoresizingMask = [ .flexibleWidth, .flexibleHeight ]
    self.view.addSubview(mapView)
 
    // Set up the MapsGL ``MapboxMapController``, which will handling adding/removing
    // MapsGL weather layers to the ``MapboxMaps.MapView``.
    let mapController = MapboxMapController(
        map: mapView,
        account: XweatherAccount(id: xweatherClientID, secret: xweatherClientSecret)
    )
 
    // Once the map has completed initial load…
    loadSubscription = mapController.subscribe(to: MapEvents.Load.self) { _ in
        // Add MapsGL map layer(s).
        try! mapController.addWeatherLayer(config: WeatherService.Temperatures(service: mapController.service))
    }
}