MapContext.showRoute

Get the default walking route planned. Only one route is displayed.

Note:

The IDE simulator cannot obtain the return values. Use the real development environment to obtain the return values.

Parameters

PropertyType

Required

Description
searchTypeStringNo

Valid values are:

  • walk: walking
  • bus: public transit
  • drive: driving
  • ride: bicycling

The default value is walk.

startLatNumberYesThe latitude of the start point.
startLngNumberYesThe longitude of the start point.
endLatNumberYesThe latitude of the end point.
endLngNumberYesThe longitude of the end point.
throughPointsArrayNoA set of points on the route. It is only available for driving guidance, that is, available when the value of

searchType is drive.

routeColorHexColorNoThe color of the route. This parameter takes effect only in 2D maps.
iconPathStringNo The texture of the route. In base library v1.11.0 and earlier versions, this parameter takes precedence over

routeColor in 3D maps. Routes are covered by texture instead of a solid color. It's suggested that this parameter is not specified in base library v1.13.0 and later versions, because a default texture pattern is provided in 3D maps. It's also suggested to set the size of the image to an integer power of 2, such as 64*64.

iconWidthIntNoThe width of the texture. This parameter takes effect only in base library v1.11.0 and earlier versions. It's suggested that this parameter is not specified in base library v1.13.0 and later versions, because a default texture width is set in 3D maps.
routeWidthIntNoThe width of the route. This parameter takes effect only when texture is not used. It's suggested that this parameter is not specified in base library v1.13.0 and later versions, because a default value is set in 2D maps and it is no longer required in 3D maps.ww
zIndexIntNoThe Z-axis index of the overlay.
modeIntNoOnly supported for driving and public transit modes. See Mode values for details.
cityStringYesRequired in the public transit mode.
destinationCityString YesRequired in the cross-city public transit mode.

Mode values

ModeBusDrive
0Fastest routeSpeed first (time).
1Most economical routeLeast cost (Choose the fastest toll-free route.)
2Minimum transfersShortest distance.
3Shortest walking distanceAvoid expressways.
4Coziest routeReal-time route planning (to avoid traffic jams).
5Avoid subway Multiple strategies (comprehensively considering the speed first, least cost, and shortest distance strategies).
6-Avoid highways.
7-Avoid highway and toll roads.
8-Avoid toll roads and traffic jams.
9-Avoid highways, toll roads, and traffic jams.

Success callback function

The type of the incoming parameter is Object with the following attributes:

PropertyTypeDescription
successBooleanIndicates whether the API operation is successful.
distanceNumberDistance.
durationNumberTime in seconds.

Sample code

copy
//.js
onReady() {
// Call my.createMapContext to obtain the map context.
this.mapCtx.showRoute({
    searchType: "walk",         // searchType: "walk", "bus", "drive", "ride". Default value: walk. Added in v10.1.50.
    startLat: 1.339712,        // The latitude of the start point.
    startLng: 103.855457,       // The longitude of the start point.
    endLat: 1.342983,         //  The latitude of the end point.
    endLng: 103.867935,        // The longitude of the end point.
    throughPoints: [{ lat: 1.343573, lng: 103.861916 }],// A set of points on the route. It is only available for driving planning, that is, available when searchType="drive". Added in v10.1.50.
    routeColor: '#FFB90F',       // The color of the route. This parameter takes effect only in 2D maps in versions later than 10.1.50.
    iconWidth: 10,           // The width of the texture. In v10.1.35, this parameter takes effect only when iconPath is specified. We recommend that you do not specify this parameter in v10.1.50. A default texture width is set in 3D maps.
    routeWidth: 10,          // The width of the route. This parameter takes effect when texture is not used. We recommend that you do not specify this parameter in v10.1.50, because a default value is set in 2D maps and it is no longer required in 3D maps.
    zIndex: 4,             // The z-axis index of the overlay 10.1.35
    mode: 0,             // Only supported in driving and public transit modes. For more information about its values, see the mode values list below.
    city: 'Singapore',         // Required in public transit mode.
    destinationCity: 'Singapore',    // Required in cross-city public transit mode.
    success: method(res) {
     console.log(res, 2323)
    }
});
console.log(1121)
},
onLoad() {
//  this.mapCtx = my.createMapContext('map');
this.mapCtx = my.createMapContext('map');
this.setData({
    includePoints:[ {
     latitude: 1.347016,
    longitude: 103.860167,
    },{
     latitude: 1.351628,
    longitude: 103.863718,
    }]
})
}
copy
//.axml
<map
     id="map"
     customMapStyle="light"
     longitude="{{longitude}}"
     latitude="{{latitude}}"
     scale="{{scale}}"
     controls="{{controls}}"
     onControlTap="controltap"
     markers="{{markers}}"
     onMarkerTap="markertap"
     polyline="{{polyline}}"
     polygon="{{polygon}}"
     circles="{{circles}}"
     onRegionChange="regionchange"
     onTap="tap"
     onCalloutTap="callouttap"
     show-location style="width: 100%; height: 200px;"
     include-points="{{includePoints}}"
     ground-overlays="{{ground-overlays}}">

Sample of the success callback function

copy
{
    distance:328,
    duration:262,
    success:true
}