Maps SDK for Web V6 (Deprecated)

Migrate from version 5 - the Services library

Overview of the tutorial

This tutorial covers basic use cases to help you switch our services. For example, switching the Routing API or Search API services from version 5 of the Maps SDK for Web to our new version. We will use code examples to explain the main differences between the SDKs.

You can check how to migrate map displaying here: Migrate from version 5 - the Maps library

Prerequisites

To start using the latest version of the TomTom Maps SDK for Web you need the following:

Displaying a route/directions

Here we have the code to display a route from point A to point B on the map.

Version 5 of the Maps SDK for Web

tt.services
.calculateRoute({
key: "<your-api-key>",
locations: "-122.510601,37.768014:-122.478468,37.769167",
})
.go()
.then(function (response) {
var geojson = response.toGeoJson()
map.addLayer({
id: "route",
type: "line",
source: {
type: "geojson",
data: geojson,
},
paint: {
"line-color": "#00d7ff",
"line-width": 8,
},
})
var bounds = new tt.LngLatBounds()
geojson.features[0].geometry.coordinates.forEach(function (point) {
bounds.extend(tt.LngLat.convert(point))
})
map.fitBounds(bounds, { padding: 20 })
})

Latest version of the Maps SDK for Web

tt.services
.calculateRoute({
key: "<your-api-key>",
locations: "-122.510601,37.768014:-122.478468,37.769167",
})
.then(function (response) {
var geojson = response.toGeoJson()
map.addLayer({
id: "route",
type: "line",
source: {
type: "geojson",
data: geojson,
},
paint: {
"line-color": "#00d7ff",
"line-width": 8,
},
})
var bounds = new tt.LngLatBounds()
geojson.features[0].geometry.coordinates.forEach(function (point) {
bounds.extend(tt.LngLat.convert(point))
})
map.fitBounds(bounds, { padding: 20 })
})

Version 5 of the Maps SDK for Web

tt.services
.fuzzySearch({
key: "<your-api-key>",
query: "pizza",
})
.go()
.then(function (result) {
console.log(result)
})

Latest version of the Maps SDK for Web

tt.services
.fuzzySearch({
key: "<your-api-key>",
query: "pizza",
})
.then(function (result) {
console.log(result)
})

As you can see the only difference here is that we no longer call the service by using .go() method. We do this by directly calling a service function.

Differences in APIs

Here is a summary of the most important updates in the services library: