目录

Walking Route Planning in Batches

Function

Plans walking routes between multiple places.

Scenario

This function is applicable to high concurrency scenarios, for example, package delivery. In this scenario, the function can calculate routes between multiple start points and end points, and find the start points and end points required for package delivery.

Restrictions

Prototype

Protocol

HTTPS POST

Direction

Your server -> Navi Kit server

URL

https://mapapi.cloud.huawei.com/mapApi/v1/routeService/walkingMatrix?key=API KEY

NOTE:
  1. For details about how to obtain an API key, please refer to Obtaining the API Key.
  2. You need to call the URLEncoder.encode("Your apiKey", "UTF-8") method to encode the API key using encodeURI. For example, if the original API key is ABC/DFG+, the conversion result is ABC%2FDFG%2B.

Data Format

Request: Content-Type: application/json

Response: Content-Type: application/json

Query Parameters

Parameter

Mandatory

Type

Description

key

Yes

String

Authentication key. For details about how to obtain one, please refer to Obtaining the API Key.

Request Parameters

Request Body

Parameter

Mandatory

Type

Description

origin

Yes

Coordinate[]

Longitudes and latitudes of the start points. A maximum of 100 start points are allowed.

destination

Yes

Coordinate[]

Longitudes and latitudes of the end points. A maximum of 100 end points are allowed.

NOTE:
  • The number of start points multiplying the number of end points must be less than 100.
  • The linear distance between the start point and end point cannot exceed 150 km.

language

No

String(<=6)

Language of the returned result. Currently, only zh_CN (Chinese) and en (English) are supported.

avoid

No

int[]

Specified policy for calculating routes. The options are as follows:

  • 0: Take the least time.
  • 8: Avoid ferries.

The default value is 0.

Request Example

POST https://mapapi.cloud.huawei.com/mapApi/v1/routeService/walkingMatrix?key=API KEY HTTP/1.1 
Content-Type: application/json 
Accept: application/json 
{
    "origins": [
        {
            "lng": 2.359782,
            "lat": 48.862544
        },
        {
            "lng": 2.358537,
            "lat": 48.861443
        }
    ],
    "destinations": [
        {
            "lng": 2.361702,
            "lat": 48.86042
        }
    ],
    "language": "en"
}

Response Parameters

When the status code is 200:

Response Header

Parameter

Mandatory

Type

Description

Content-Type

Yes

application/json

Response data format.

Response Body

Parameter

Type

Description

returnCode

String

Result code. For details, please refer to Result Codes.

returnDesc

String

Result description.

originAddresses

String[]

Start point details.

destinationAddresses

String[]

End point details.

rows

Row[]

Distances and journey time of routes between start points and end points.

Response Example

When the status code is 200:

HTTP/1.1 200 OK
Content-type: application/json
{
    "originAddresses": [
        "76, Rue des Archives, 75003, Le Marais, 3e Arrondissement, Paris, Île-de-France, France",
        "62, Rue des Archives, 75003, 3e Arrondissement, Paris, Île-de-France, France"
    ],
    "returnCode": "0",
    "destinationAddresses": [
        "101 T, Rue Des Coutures Saint-Gervais, 75003, 3e Arrondissement, Paris, Île-de-France, France"
    ],
    "rows": [
        {
            "cells": [
                {
                    "duration": 268.684,
                    "durationText": "4min",
                    "distance": 353.573,
                    "distanceText": "354m",
                    "status": 0
                }
            ]
        },
        {
            "cells": [
                {
                    "duration": 256.39,
                    "durationText": "4min",
                    "distance": 352.386,
                    "distanceText": "352m",
                    "status": 0
                }
            ]
        }
    ],
    "returnDesc": "OK"
}

Call Example

public class MatrixService {
    public static final String ROOT_URL = "https://mapapi.cloud.huawei.com/mapApi/v1/routeService/walkingMatrix";

    public static final String connection = "?key=";

    public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

    public static void matrixWalking(String apiKey) throws UnsupportedEncodingException {
        JSONObject json = new JSONObject();
        JSONArray origin = new JSONArray();
        JSONObject startingPoint_1 = new JSONObject();
        JSONObject startingPoint_2 = new JSONObject();
        JSONArray destination = new JSONArray();
        JSONObject endPoint = new JSONObject();

        try {
            startingPoint_1.put("lng", 2.359782);
            startingPoint_1.put("lat", 48.862544);

            startingPoint_2.put("lng", 2.358537);
            startingPoint_2.put("lat", 48.861443);

            origin.put(0, startingPoint_1);
            origin.put(1, startingPoint_2);

            endPoint.put("lng", 2.361702);
            endPoint.put("lat", 48.860420);

            destination.put(0, endPoint);

            json.put("origins", origin);
            json.put("destinations", destination);
            json.put("language", "en");
        } catch (JSONException e) {
            Log.e("error", e.getMessage());
        }
        RequestBody body = RequestBody.create(JSON, String.valueOf(json));

        OkHttpClient client = new OkHttpClient();
        Request request =
            new Request.Builder().url(ROOT_URL + connection + URLEncoder.encode(apiKey, "UTF-8"))
                .post(body)
                .build();

        client.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Log.e("MatrixWalking", e.toString());
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                Log.d("MatrixWalking", response.body().string());
            }
        });
    }
}

Debugging Using Postman

You can use Postman to debug this API online.