This capability quickly calculates distances and travel times between multiple departure places and destinations across different transportation modes, including driving, walking, and cycling, in batches.
The following table describes APIs for route planning, which are mainly provided by methods in the navi namespace. For more information about the APIs, please refer to API Reference.
| API | Description |
|---|---|
| getDrivingMatrix(params: DrivingMatrixParams): Promise<MatrixResult> | Performs batch route computation for driving. |
| getDrivingMatrix(context: common.Context, params: DrivingMatrixParams): Promise<MatrixResult> | Performs batch route computation for driving. The context can be passed. |
| getWalkingMatrix(params: MatrixParams): Promise<MatrixResult> | Performs batch route computation for walking. |
| getWalkingMatrix(context: common.Context, params: MatrixParams): Promise<MatrixResult> | Performs batch route computation for walking. The context can be passed. |
| getCyclingMatrix(params: MatrixParams): Promise<MatrixResult> | Performs batch route computation for cycling. |
| getCyclingMatrix(context: common.Context, params: MatrixParams): Promise<MatrixResult> | Performs batch route computation for cycling. The context can be passed. |
| DrivingMatrixParams | Parameters for batch driving route computation. |
| MatrixParams | Parameters for batch walking and cycling route computation. |
| MatrixResult | Result of batch route computation. |
Import required modules.
import { navi } from '@kit.MapKit';
import { BusinessError } from '@kit.BasicServicesKit'; This capability plans driving routes between multiple departure places and destinations based on their coordinates. This capability can:
Support future travel planning.
Plan routes based on real-time traffic conditions.
Support route preferences, for example, taking the least time, avoiding toll roads, avoiding highways, and taking the shortest distance.
To ensure performance and accuracy, the number of departure places multiplied by the number of destinations in a single request must be less than 100.
async testDrivingMatrix() {
let params: navi.DrivingMatrixParams = {
// Longitude and latitude of the departure place.
origins: [{
latitude: 31.9844,
longitude: 118.766253
}, {
latitude: 31.9644,
longitude: 118.746253
}],
// Longitude and latitude of the destination.
destinations: [{
latitude: 31.9344,
longitude: 118.706253
}],
// Time estimation mode.
trafficMode: 2,
language: 'en'
};
try {
const result = await navi.getDrivingMatrix(params);
console.info(`Succeeded in getting driving matrix. result is ${JSON.stringify(result)}`);
} catch (error) {
const err: BusinessError = error as BusinessError;
console.error(`Failed in getting driving matrix. Code is ${err.code}, message is ${err.message}`);
}
} This capability plans walking routes between multiple departure places and destinations based on their coordinates. This capability can:
Plan walking routes within a distance of 150 kilometers.
Take travel policies (such as taking the least time or avoiding ferries) into consideration for route planning.
To ensure performance and accuracy, the number of departure places multiplied by the number of destinations in a single request must be less than 100.
async testWalkingMatrix() {
let params: navi.MatrixParams = {
// Longitude and latitude of the departure place.
origins: [
{
latitude: 31.9844,
longitude: 118.766253
}, {
latitude: 31.9644,
longitude: 118.746253
}],
// Longitude and latitude of the destination.
destinations: [{
latitude: 31.9344,
longitude: 118.706253
}],
language: 'en'
};
try {
const result = await navi.getWalkingMatrix(params);
console.info(`Succeeded in getting walking matrix. result is ${JSON.stringify(result)}`);
} catch (error) {
const err: BusinessError = error as BusinessError;
console.error(`Failed in getting walking matrix. Code is ${err.code}, message is ${err.message}`);
}
} This capability plans cycling routes between multiple departure places and destinations based on their coordinates. This capability can:
Plan cycling routes within a distance of 500 kilometers.
Take travel policies (such as taking the least time or avoiding ferries) into consideration for route planning.
To ensure performance and accuracy, the number of departure places multiplied by the number of destinations in a single request must be less than 100.
async testCyclingMatrix() {
let params: navi.MatrixParams = {
// Longitude and latitude of the departure place.
origins: [{
latitude: 31.9844,
longitude: 118.766253
}, {
latitude: 31.9644,
longitude: 118.746253
}],
// Longitude and latitude of the destination.
destinations: [{
latitude: 31.9344,
longitude: 118.706253
}],
language: 'en'
};
try {
const result = await navi.getCyclingMatrix(params);
console.info(`Succeeded in getting cycling matrix. result is ${JSON.stringify(result)}`);
} catch (error) {
const err: BusinessError = error as BusinessError;
console.error(`Failed in getting cycling matrix. Code is ${err.code}, message is ${err.message}`);
}
}