簡體   English   中英

Android Google地圖 - 如何在相同的細分中划分Google地圖路線?

[英]Android Google Maps - How to divide Google Maps route in equal segments?

在我的自定義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中的點不是均勻分散的。

任何幫助將不勝感激。

請參閱此簡單代碼。

  1. 獲取文件

      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); 
  2. 畫線:

      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); 
  3. 添加點

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM