承载协议 | HTTPS POST |
|---|---|
接口方向 | 开发者 -> 华为导航服务器 |
接口URL | https://mapapi.cloud.huawei.com/mapApi/v1/routeService/walking?key=API KEY 说明:
|
数据格式 | 请求消息:Content-Type: application/json 响应消息:Content-Type: application/json |
Request Body
参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
origin | 是 | 起点的经纬度。 | |
destination | 是 | 终点的经纬度。 | |
language | 否 | String(<=6) | 文字指引/描述的语种。目前只支持zh_CN和en。 |
avoid | 否 | int[] | 表示计算出的路径应避免所指示的特性。取值包括:
默认值为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
状态码为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());
}
});
}
}