The easiest way of getting official and up to date traffic data for the geographical region of Denmark.
- Traffic events
- Roadwork events
- Road segments congestion status
- Road segments deicing status in winter
- Condition of road segments in winter
- Request data from within geographical bounding box
- Request single entity by
tag
The library can be installed using one of the below methods:
Add VejdirektoratetSDK
to your Package.swift
import PackageDescription
let package = Package(
dependencies: [
package(url: "https://github.com/Vejdirektoratet/sdk-ios.git", "1.0.2")
])
Add the following line to your Podfile:
pod 'VejdirektoratetSDK'
Then run
$ pod install
Be sure to open the generated workspace in Xcode.
An API key is needed when requesting data through this SDK. To generate an API key you have to:
- Create an account on the website of The Danish Road Directorate.
- Generate the API key (while being logged in to the account created in step 1)
The following request will return the current Traffic and Roadwork events for the specified region. The returned data will be objects subclassing ListEntity
suitable for a list representation due to the parameter viewType = .List
.
import VejdirektoratetSDK
VejdirektoratetSDK.request(entityTypes: [.Traffic, .RoadWork],
region: mapView.region,
viewType: .List,
apiKey: self.apiKey) { result in
switch result {
case .entities(let entities):
// Handle entities
case .error(let error):
// Handle error
default:
break
}
}
The method returns a HTTP.Request
which can be cancelled by calling
request.cancel()
The entityTypes
parameter is a list of EntityType
objects defining what data is requested. The available EntityTypes are:
- Traffic (traffic events e.g. accidents)
- Roadwork (roadworks)
- TrafficDensity (traffic congestion of road segments)
- WinterDeicing (deicing status of road segments)
- WinterCondition (condition of roadsegments in winter e.g. is the segment in risk of being slippery?)
NOTE: TrafficDensity
, WinterDeicing
and WinterCondition
can only be used in combination with viewType = .Map
The region
parameter is a bounding box of type MKCoordinateRegion
describing the area for which to get data.
Omitting this parameter will return data for the entire region of Denmark.
The parameter zoom
is a Google-maps style zoom level describing in which resolution the geometrical information should be returned.
NOTE: This parameter is only relevant for viewType = .Map
The viewType
parameter defines in which format the data should be returned. Data can be returned in two formats aimed for different purposes.
- List - Returns
ListEntity
objects (for list representations of data) - Map - Returns
MapEntity
objects (contains geometrical information for a map representation of the data)
The apiKey
parameter is required to get access to the available data.
It can be generated on The Danish Road Directorate's website
The completion
parameter is a callback function for handling the result of the request. The result is returned in form of a HTTP.Result
enum.
- Result.Entities (contains a list of requested entities)
- Result.Entity (contains a single requested entity)
- Result.Error (contains a RequestError)
VejdirektoratetSDK is brought to you by The Danish Road Directorate.
This SDK is using the following libraries:
Project contributors.
VejdirektoratetSDK is released under the MIT license.