Sorry, you need to enable JavaScript to visit this website.

Map initialization

Map initialization

The main class that represents a Map is a TTMapView. The TTMapView is an interactive world map that pans and zooms in response to gestures. Use its methods to receive map-related update messages in your application as long as they conform to the TTMapViewDelegate protocol.

The basic steps for adding a map are:

  1. Set up your project as it is described in DOWNLOADS.

  2. Create the object 'TTMapView'.

  3. Obtain the keys to the constructor class.

  4. Use the 'TTMapView' object to set the map properties.

_

let builder = TTMapConfigurationBuilder.create()
let style = TTMapStyleDefaultConfiguration()
let config = builder.withMapStyleConfiguration(style).build()
let mapview = TTMapView(mapConfiguration: config)
TTMapConfigurationBuilder *builder = [TTMapConfigurationBuilder createBuilder];
TTMapStyleDefaultConfiguration *style = [[TTMapStyleDefaultConfiguration alloc] init];
TTMapConfiguration *configuration = [[builder withMapStyleConfiguration:style] build];
TTMapView *mapView = [[TTMapView alloc] initWithMapConfiguration:configuration];

[Optional] Create the TTMapConfiguration object and pass it to the MapView init method. The TTMapConfiguration object allows you to configure the initial viewport and TomTom logo position.

TTMapConfiguration

Map configuration is an extra parameter that can be used to init a 'TTMapView'.

_

let mapview = TTMapView(mapConfiguration: config)
TTMapView *mapView = [[TTMapView alloc] initWithMapConfiguration:configuration];

 

TomTom Keys

The service key is added by entering it into the class constructor.

_

let mapConfig = TTMapConfigurationBuilder.create().withMapKey(<Key>).withTrafficKey(<Key>).build()
self.mapView = TTMapView(frame: view.bounds, mapConfiguration: mapConfig)
TTMapConfiguration *mapConfig = [[[[[TTMapConfigurationBuilder createBuilder] withMapKey:<Key>] withTrafficKey:<Key>] build];
self.mapView = [[TTMapView alloc] initWithFrame:self.view.bounds mapConfiguration:mapConfig];

 

TomTom Logo

When using the Maps SDK for iOS, it is required that the TomTom logo is always visible. By default, the TomTom logo is located at the bottom-left corner of the map. However, you can easily customize its position to meet your app design by passing the TTLogoPosition object to your map configuration object.

_

let logoPosition = TTLogoPosition(verticalPosition: .bottom, horizontalPosition: .right)
let mapConfig = TTMapConfigurationBuilder.create().withTomTomLogoPosition(logoPosition).build()
let mapview = TTMapView(mapConfiguration: mapConfig)
TTLogoPosition *logoPosition = [[TTLogoPosition alloc] initWithVerticalPosition:bottom horizontalPosition:left];
TTMapConfiguration *mapConfig = [[[[TTMapConfigurationBuilder createBuilder] withViewportTransform:viewportTransform] withTomTomLogoPosition:logoPosition] build];
TTMapView *mapView = [[TTMapView alloc] initWithMapConfiguration:mapConfig];

 

ViewportTransform

If you want to init a 'TTMapView' centered on specific place with a custom bearing and pitch, you should check the TTViewportTransform param of TTMapConfiguration.

_

let viewportTransform = TTCenterOnGeometryBuilder.create(withGeometry: [
        .init(latitude: 52.3274167028, longitude: 4.72924173),
        .init(latitude: 52.43106373, longitude: 5.0310596876),
        .init(latitude: 52.43106373, longitude: 4.72924173),
        .init(latitude: 52.3274167028, longitude: 4.72924173),
    ], withPadding: .zero)
        .withPitch(30)
        .withBearing(-90)
        .build()
let mapConfig = TTMapConfigurationBuilder.create().withViewportTransform(viewportTransform).build()
self.mapView = TTMapView(frame: view.bounds, mapConfiguration: mapConfig)
NSArray<CLLocation *> *geometry = @[[[CLLocation alloc] initWithLatitude:52.3274167028 longitude:4.72924173], [[CLLocation alloc] initWithLatitude:52.43106373 longitude:5.0310596876], [[CLLocation alloc] initWithLatitude:52.43106373 longitude:4.72924173],[[CLLocation alloc] initWithLatitude:52.3274167028 longitude:4.72924173]];
TTCenterOnGeometry *viewportTransform = [[[[TTCenterOnGeometryBuilder createWithGeometry:geometry withPadding:UIEdgeInsetsZero] withPitch:30] withBearing:-90] build];
TTMapConfiguration *mapConfig = [[[[TTMapConfigurationBuilder createBuilder] withViewportTransform:viewportTransform] build];
TTMapView *mapView = [[TTMapView alloc] initWithMapConfiguration:mapConfig];

 

OnMapReadyCompletion:

_

self.mapView.onMapReadyCompletion {
    //
}
[self.mapView onMapReadyCompletion:^{
    //
}];