Getting started | Mobile SDK | 2GIS Documentation

Getting started

First you need to contact 2GIS technical support to get a new key. Be sure to specify the appId of the application for which the key will be generated.

To begin working with the SDK, create a Container object, which will store all map entities.

To create it, you need to specify path to your key file via ApiKeyOptions. When specifying ApiKeyOptions.default, the file must be added to the application root.

// Key file.
let apiKeyOptions = ApiKeyOptions(apiKeyFile: File(path: "Path to key info file"))

// Создание контейнера для доступа к возможностям SDK.
let sdk = DGis.Container(apiKeyOptions: apiKeyOptions)

Note that DGis.Container can be created in single instance.

Additionally, you can specify logging settings (LogOptions) and HTTP client settings (HTTPOptions) such as timeout and caching.

// Logging settings.
let logOptions = LogOptions(osLogLevel: .info)

// HTTP client settings.
let httpOptions = HTTPOptions.default

// Geopositioning settings.
let positioningServices: IPositioningServicesFactory = CustomPositioningServicesFactory()

// Consent to personal data processing.
let dataCollectionOptions = DataCollectionOptions(dataCollectionStatus: .agree)

// Creating the Container.
let sdk = DGis.Container(
	apiKeyOptions: apiKeyOptions,
	logOptions: logOptions,
	httpOptions: httpOptions,
	positioningServices: positioningServices,
	dataCollectionOptions: dataCollectionOptions

To override some SDK operation settings, a file in VendorConfig format is used, which is passed during SDK container initialization.

The file must be added to the bundle when building the application and an instance of the File class must be created. For a file added to the root of the bundle and named vendor-config.json, the code will look like this:

let vendorConfigFile = Bundle.main.path(forResource: "vendor-config", ofType: "jsonx").map { File(path: $0) }

Further, this variable must be passed with the vendorConfigFile parameter when initializing Container:

let sdk = DGis.Container(vendorConfigFile: vendorConfigFile)