在我自定义的Google地图中,我使用此网址在两个地点(比如Pune到Mumbai)之间绘制路线
https://maps.googleapis.com/maps/api/directions/json?origin=Pune&destination=Mumbai&sensor=false&mode=driving&alternatives=false
解析此响应我获得源和目标之间的点数并将其存储在ArrayList
ArrayList<LocationModel> listAllPoints = getPoints();
此ArrayList
包含大约2600个点。
我的问题是,如何将此路线划分为10个相等的段,即包括源和目的地在内的总共11个点。喜欢这个
| A | B | C | D | E | F | G | H |我| J |
其中| =每个点,Character = segment
A和B之间的距离,B和C,C和D应相等。
我应该可以通过在11个部分中分割listAllPoints
来做到这一点,但问题是,listAllPoints
内的点不是均匀分散的。
非常感谢任何帮助。
答案 0 :(得分:0)
参考这个简单的代码。
获取文档
String url = "http://maps.googleapis.com/maps/api/directions/xml?"
+ "origin=" + start.latitude + "," + start.longitude
+ "&destination=" + end.latitude + "," + end.longitude
+ "&sensor=false&units=metric&mode=driving";
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(url);
HttpResponse response = httpClient.execute(httpPost, localContext);
InputStream in = response.getEntity().getContent();
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = builder.parse(in);
画线:
ArrayList<LatLng> directionPoint = v2GetRouteDirection
.getDirection(document);
PolylineOptions rectLine = new PolylineOptions().width(10)
.color(Color.RED);
for (int i = 0; i < directionPoint.size(); i++) {
rectLine.add(directionPoint.get(i));
}
// Adding route on the map
mGoogleMap.addPolyline(rectLine);
添加点
MarkerOptions markerOptions = new MarkerOptions();
Bitmap icon = BitmapFactory.decodeResource(
EMaps2.this.getResources(), R.drawable.pointa);
markerOptions
.icon(BitmapDescriptorFactory.fromBitmap(icon));
markerOptions.position(fromPosition);
markerOptions.title("Point A");
mGoogleMap.addMarker(markerOptions);