目录

路径规划-步行

功能介绍

提供两点之间步行路径规划能力。

场景描述

无

使用约束

接口原型

承载协议

HTTPS POST

接口方向

开发者 -> 华为导航服务器

接口URL

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

说明:
  1. 获取API KEY的方式请参见获取API key。
  2. 使用API key时需要调用URLEncoder.encode("Your apiKey", "UTF-8")方法对API key进行encodeURI编码。例如:原始API key:ABC/DFG+ ,转换结果:ABC%2FDFG%2B。

数据格式

请求消息:Content-Type: application/json

响应消息:Content-Type: application/json

查询参数

参数

是否必选

参数类型

描述

key

是

String

鉴权秘钥,申请参见获取API key。

请求参数

Request Body

参数

是否必选

参数类型

描述

origin

是

Coordinate

起点的经纬度。

destination

是

Coordinate

终点的经纬度。

language

否

String(<=6)

文字指引/描述的语种。目前只支持zh_CN和en。

avoid

否

int[]

表示计算出的路径应避免所指示的特性。取值包括:

  • 0:时间最短
  • 8:避免轮渡

默认值为0。

请求示例

POST https://mapapi.cloud.huawei.com/mapApi/v1/routeService/walking?key=API KEY   HTTP/1.1 
Content-Type: application/json 
Accept: application/json
{ 
    "origin": { 
        "lng": -4.66529, 
        "lat": 54.216608 
    }, 
    "destination": { 
        "lng": -4.66552, 
        "lat": 54.2166
    } 
}

响应参数

状态码为200时:

Response Header

参数

是否必选

参数类型

描述

Content-Type

是

application/json

响应消息的数据格式。

Response Body

参数

参数类型

描述

returnCode

String

返回码,具体请参见错误码。

returnDesc

String

返回值描述。

routes

Route[]

从起点到目的地的规划路径。如果没有结果,返回空数组。

响应示例

状态码为200时:

HTTP/1.1 200 OK
Content-type: application/json
{
    "routes": [
        {
            "dstInDiffTimeZone": 0,
            "crossCountry": 0,
            "hasRestrictedRoad": 0,
            "crossMultiCountries": 0,
            "dstInRestrictedArea": 0,
            "overviewPolyline": "gcssmvffdgfq;gcssmvffb5wp;gcssmvfdzq9v",
            "paths": [
                {
                    "duration": 8.459,
                    "durationText": "1min",
                    "durationInTrafficText": "1min",
                    "durationInTraffic": 8.459,
                    "distance": 11.749,
                    "startLocation": {
                        "lng": -4.66529166511,
                        "lat": 54.2166064467
                    },
                    "startAddress": "German the United Kingdom",
                    "distanceText": "12m",
                    "steps": [
                        {
                            "orientation": 0,
                            "durationText": "1min",
                            "distance": 11.749,
                            "roadName": "Poortown Road",
                            "duration": 8.459,
                            "startLocation": {
                                "lng": -4.66529166511,
                                "lat": 54.2166064467
                            },
                            "instruction": "",
                            "action": "end",
                            "distanceText": "12m",
                            "endLocation": {
                                "lng": -4.66544272739,
                                "lat": 54.21666386525
                            },
                            "polyline": [
                                {
                                    "lng": -4.66529167,
                                    "lat": 54.21660645
                                },
                                {
                                    "lng": -4.6654048,
                                    "lat": 54.2166481
                                },
                                {
                                    "lng": -4.66544273,
                                    "lat": 54.21666387
                                }
                            ]
                        }
                    ],
                    "endLocation": {
                        "lng": -4.66544272739,
                        "lat": 54.21666386525
                    },
                    "endAddress": "German the United Kingdom"
                }
            ],
            "bounds": {
                "southwest": {
                    "lng": -4.66552194,
                    "lat": 54.21660614
                },
                "northeast": {
                    "lng": -4.66529083,
                    "lat": 54.21669583
                }
            },
            "hasStairs": 0,
            "hasFerry": 0
        }
    ],
    "returnCode": "0",
    "returnDesc": "OK"
}

调用示例

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

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

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

    public static void Walking(String apiKey) throws UnsupportedEncodingException {
        JSONObject json = new JSONObject();
        JSONObject origin = new JSONObject();
        JSONObject destination = new JSONObject();

        try {
            origin.put("lng", -4.66529);
            origin.put("lat", 54.216608);

            destination.put("lng", -4.66552);
            destination.put("lat", 54.2166);

            json.put("origin", origin);
            json.put("destination", destination);
        } 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("Walking", e.toString());
            }

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

Postman调试

您可以使用Postman在线调试此接口。