承载协议 | HTTPS POST |
|---|---|
接口方向 | 开发者 -> 华为导航服务器 |
接口URL | https://mapapi.cloud.huawei.com/mapApi/v1/routeService/snapToRoads?key=API KEY 说明:
|
数据格式 | 请求消息:Content-Type: application/json 响应消息:Content-Type: application/json |
POST https://mapapi.cloud.huawei.com/mapApi/v1/routeService/snapToRoads?key=API KEY HTTP/1.1
Content-Type: application/json
Accept: application/json
{
"points": [
{
"lng": 9.056670927077944,
"lat": 52.88005648589605
}
]
} 状态码为200时:
Response Header
参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
Content-Type | 是 | application/json | 响应消息的数据格式。 |
Response Body
参数 | 参数类型 | 描述 |
|---|---|---|
returnCode | String | 返回码,具体请参见错误码。 |
returnDesc | String | 返回值描述。 |
responseTime | int | 耗时,单位:毫秒。 |
snappedPoints | 道路吸附点。 |
状态码为200时:
HTTP/1.1 200 OK
Content-type: application/json
{
"returnCode": "0",
"responseTime": 0,
"snappedPoints": [
{
"lng": 9.0566728,
"roadID": "00004436-3800-0400-0000-000001b0ae42",
"lat": 52.88005949
}
],
"returnDesc": "OK"
} class TestSnapToRoads {
public static final String ROOT_URL = "https://mapapi.cloud.huawei.com/mapApi/v1/routeService/snapToRoads";
public static final String connection = "?key=";
public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
public static void snapToRoads(String apiKey) throws UnsupportedEncodingException {
JSONObject json = new JSONObject();
try {
JSONArray points = new JSONArray();
JSONObject startingPoint_1 = new JSONObject();
JSONObject startingPoint_2 = new JSONObject();
startingPoint_1.put("lng", 2.359782);
startingPoint_1.put("lat", 48.862544);
startingPoint_2.put("lng", 2.358537);
startingPoint_2.put("lat", 48.861443);
points.put(0, startingPoint_1);
points.put(1, startingPoint_2);
json.put("points", points);
} catch (JSONException e) {
Log.e("snapToRoads failed : {}", e.getMessage());
}
RequestBody body = RequestBody.create(JSON, json.toJSONString());
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("snapToRoads onFailure : {}", e.toString());
}
@Override
public void onResponse(Call call, Response response) throws IOException {
Log.d("snapToRoads onResponse : {}", response.body().string());
}
});
}
}