Getting started
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
)
Vendor Config
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)
Working with offline data
Mobile SDK (the Full version) allows you to work with map, directory and routing data offline from preloaded packages. This can be helpful when the network connection is low or missing.
To configure the offline mode:
-
Ensure that your access key contains proper rights for working with offline data. You can request access to offline data for all components (map, directory, routing) or select only the required ones.
-
Use TerritoryManager to download data files for territories where your application must work offline.
-
Configure SDK components for working with preloaded data:
- Map: create a data source and specify the required working mode.
- Directory: use the required method of creating an object directory.
- Routing: a hybrid mode is used by default. For details, see the routing documentation.