Hi I am using Async task to grab longitude and latitude in an JSONArray. I am able to draw polyline but I cannot figure out how to draw put in the start and the end of the polyline.
// Initialization
ArrayList<LatLng> polylines = new ArrayList<LatLng>();
JSONArray lines = null;
JSONObject jsonPolyline;
LatLng polyline;
And here is what I have on the onPostExecute
of my AsyncTask
lines = json.getJSONArray("track");
for (int i = 0; i < lines.length(); i++) {
jsonPolyline = lines.getJSONObject(i);
polyline = new LatLng(Double.valueOf(jsonPolyline.getString("lat")),
Double.valueOf(jsonPolyline.getString("lon")));
polylines.add(polyline);
}
/*call the polyline */
myMap.addPolyline(new PolylineOptions().addAll(polylines).width(2.0f).color(Color.GREEN));
I tried using , ListIterator
but since my Arraylist is <latlng>
, I cannot get the first and last element on the arraylist.
How can I get the first and last element on my arraylist so that I can draw marker on the start and end position.
Every Java List<>
implements get()
and size()
methods:
first = polylines.get(0);
last = polylines.get(polyline.size() -1);