How can I get a polyline
out of the Directions API JSON response?
如何从Directions API JSON响应中获取折线?
Using the overview_polyline
is not an option as it is only a smoothened version of the actual polyline
.
使用overview_polyline不是一个选项,因为它只是实际折线的平滑版本。
I also tried getting the start and end location coordinates from the steps, however those will only give me a very inaccurate polyline
, because they only contain a few coordiantes.
我也尝试从步骤中获取开始和结束位置坐标,但是这些只会给我一个非常不准确的折线,因为它们只包含一些坐标。
How can I get an accurate polyline
out of the Directions response?
如何从Directions响应中获得准确的折线?
EDIT: Using @SaxonDruce answer, I can get accurate polylines however, they look like this:
编辑:使用@SaxonDruce答案,我可以获得准确的折线,但它们看起来像这样:
2 个解决方案
#1
0
Based on the sample response, you'll need something equivalent to:
根据样本响应,您需要的东西相当于:
response.routes[0].legs[0].steps[i].polyline.points
So, get the first route, then the first leg, then loop over the steps, then get the polyline, then get the points.
因此,获取第一条路线,然后是第一条路线,然后循环步骤,然后获取折线,然后获得积分。
#2
0
To add to saxon druce's answer, You can loop over all the steps of first leg and combine all the points to form a polyline.
要添加到saxon druce的答案,您可以循环第一条腿的所有步骤并将所有点组合以形成折线。
List<LatLng> points = new ArrayList<>();
for (DirectionsStep step : legs[i].steps) {
points.addAll(step.polyline.decodePath());
}
EncodedPolyline legPolyline = new EncodedPolyline(points);
#1
0
Based on the sample response, you'll need something equivalent to:
根据样本响应,您需要的东西相当于:
response.routes[0].legs[0].steps[i].polyline.points
So, get the first route, then the first leg, then loop over the steps, then get the polyline, then get the points.
因此,获取第一条路线,然后是第一条路线,然后循环步骤,然后获取折线,然后获得积分。
#2
0
To add to saxon druce's answer, You can loop over all the steps of first leg and combine all the points to form a polyline.
要添加到saxon druce的答案,您可以循环第一条腿的所有步骤并将所有点组合以形成折线。
List<LatLng> points = new ArrayList<>();
for (DirectionsStep step : legs[i].steps) {
points.addAll(step.polyline.decodePath());
}
EncodedPolyline legPolyline = new EncodedPolyline(points);