alb*_*alb 2 java android google-maps directions google-polyline
我正在使用谷歌地图方向Api和谷歌地图实用程序库绘制我的位置与标记之间的路径,我正在从方向Api 检索字段概述 - 折线,但绘制的折线不正确所以现在我我正在尝试逐步构建折线,但我遇到了一个问题,我能够将所有折线添加到arraylist但是现在我如何从arraylist中检索它们来解码并构建它们;
这是JSON:
{
geocoded_waypoints: [
{},
{}
],
routes: [
{
bounds: {},
copyrights: "Dados do mapa ©2017 Google, Inst. Geogr. Nacional",
legs: [
{
distance: {},
duration: {},
end_address: "14 Avenue Latécoère, 31700 Cornebarrieu, França",
end_location: {},
start_address: "R. Zeferino Brandão 9, 2005 Santarém, Portugal",
start_location: {},
steps: [
{
distance: {},
duration: {},
end_location: {},
html_instructions: "Siga para <b>noroeste</b> na <b>R. Zeferino Brandão</b> em direção a <b>Tv. de São Domingos</b>",
polyline: {
points: "k|nnF`p_t@GB{@t@MFQPMLKXETEZCVCL?@?BAD?@?DAFC|@"
},
start_location: {},
travel_mode: "DRIVING"
},
{},
Run Code Online (Sandbox Code Playgroud)
这就是我解释概述折线的方法:
...
JSONObject singleRout = (JSONObject) routes.get(0);
JSONObject overview_polyline = (JSONObject) singleRout.get("overview_polyline");
if (overview_polyline != null) {
points = overview_polyline.getString("points");
}
...
protected void fazerCaminho() {
List<LatLng> decodedPath = PolyUtil.decode(points);
if (line == null) {
line = mMap.addPolyline(new PolylineOptions()
.width(3)
.color(Color.rgb(25, 151, 152))
.geodesic(true)
.addAll(decodedPath));
} else {
line.remove();
line = mMap.addPolyline(new PolylineOptions()
.width(3)
.color(Color.rgb(25, 151, 152))
.geodesic(true)
.addAll(decodedPath));
}
}
Run Code Online (Sandbox Code Playgroud)
现在我将所有的点添加到arraylist中,如下所示:
JSONObject singlePolyline = (JSONObject) singleStep.get("polyline");
if (singlePolyline != null) {
points = singlePolyline.getString("points");
caminho.put("points" , points);
}
listaPolylines.add(caminho);
Run Code Online (Sandbox Code Playgroud)
如何解码列表中的值?
ant*_*nio 12
您可以使用PolyUtil.decode从方法谷歌地图API的Android实用工具库:
List<LatLng> decoded = PolyUtil.decode(caminho.get("points"));
Run Code Online (Sandbox Code Playgroud)
在您的情况下,如果您想从您的解码listaPolylines:
for (Map polyline : listaPolylines) {
List<LatLng> decoded = PolyUtil.decode(polyline.get("points"));
// Do something with your decoded polyline. For example drawing it on your map
mMap.addPolyline(new PolylineOptions().addAll(decoded));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5387 次 |
| 最近记录: |