Java Android谷歌地图-如何将谷歌地图路线划分为相等的部分?

Java Android谷歌地图-如何将谷歌地图路线划分为相等的部分?,java,android,google-maps,Java,Android,Google Maps,在我的自定义谷歌地图中,我使用这个URL在两个地点(比如普纳到孟买)之间画了一条路线 https://maps.googleapis.com/maps/api/directions/json?origin=Pune&destination=Mumbai&sensor=false&mode=driving&alternatives=false 解析此响应时,我会得到源和目标之间的点数,并将其存储在ArrayList ArrayList<LocationMo

在我的自定义谷歌地图中,我使用这个URL在两个地点(比如普纳到孟买)之间画了一条路线

https://maps.googleapis.com/maps/api/directions/json?origin=Pune&destination=Mumbai&sensor=false&mode=driving&alternatives=false

解析此响应时,我会得到源和目标之间的点数,并将其存储在
ArrayList

ArrayList<LocationModel> listAllPoints = getPoints();
ArrayList listalpoints=getPoints();
ArrayList
包含约2600个点

我的问题是,我如何将这条路线划分为10个相等的路段,即总共11个点,包括起点和终点。像这样

|A | B | C | D | E | F | G | H | I | J|

其中|=每个点,字符=段

A和B、B和C、C和D之间的距离应相等

我应该能够通过将
listAllPoints
划分为11个部分来实现这一点,但问题是
listAllPoints
中的点并不是均匀分散的


任何帮助都将不胜感激。

请参考此简单代码

  • 获取文档

                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);