[英]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
中的點不是均勻分散的。
任何幫助將不勝感激。
請參閱此簡單代碼。
獲取文件
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.