CommonDandy
Lurker
I am trying to draw a costume route on a Google map. The route is displayed but I get some extra polylines in it which make the route wrong.
I am drawing the lines using this method:
I am drawing the lines using this method:
Code:
// Executes in UI thread, after the parsing process protected void onPostExecute(List<List<HashMap<String, String>>> result) { ArrayList<LatLng> points = null; PolylineOptions lineOptions = null; // Traversing through all the routes for(int i=0;i<result.size();i++) { points = new ArrayList<LatLng>(); lineOptions = new PolylineOptions(); // Fetching i-th route List<HashMap<String, String>> path = result.get(i); // Fetching all the points in i-th route for(int j=0;j<path.size();j++) { HashMap<String,String> point = path.get(j); double lat = Double.parseDouble(point.get("lat")); double lng = Double.parseDouble(point.get("lng")); LatLng position = new LatLng(lat, lng); points.add(position); } // Adding all the points in the route to LineOptions lineOptions.addAll(points); lineOptions.width(7); lineOptions.color(Color.GREEN); } // Drawing polyline in the Google Map for the i-th route mGoogleMap.addPolyline(lineOptions); } [CODE]
and I am putting the coordinates of the segments using this code:
[CODE]public List<List<HashMap<String,String>>> parse(Variant variant) { List<List<HashMap<String, String>>> routes = new ArrayList<List<HashMap<String,String>>>(); try { /** Traversing all routes */ for(int i=0;i < variant.route.length; i++) { List<HashMap<String, String>> path = new ArrayList<HashMap<String, String>>(); /** Traversing all legs */ for(int j=0;j < variant.route[i].segments.length; j++) { /** Traversing all points */ for(int l=0;l < variant.route[i].segments[j].coordinate.length; l++) { HashMap<String, String> hm = new HashMap<String, String>(); hm.put("lat", Double.toString(variant.route[i].segments[j].coordinate[l].latitude)); hm.put("lng", Double.toString(variant.route[i].segments[j].coordinate[l].longitude)); path.add(hm); } }routes.add(path); } }catch (Exception e){ } return routes; } [CODE]
I dont understand what I am doing wrong. Is polyline the best solution for drawing a route on a map?