Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to call populate() from mapOverlay
    primarykey
    data
    text
    <p>I'm converting GeoPoints from a route to an overlay and inserting to the map, on the overlays list (using mapView.getOverlays()).</p> <p>On the first execution, everything went fine, but after, the map doesn't display the route overlay. After researching, I've remembered I have to call populate() to update the map overlays, but I don't know how to do that outside the ItemizedOverlay class.</p> <p>Someone could help me?</p> <p>Thanks in advance, Danniel.</p> <p>EDIT::</p> <p>Method which gets the route and parse the polyline into GeoPoints</p> <pre><code>public void drawRoute(Location from, double toLat, double toLon) { String url = RoadProvider.getUrl(from.getLatitude(), from.getLongitude(), toLat, toLon); Log.i("rotaUrl", url); JSONGet routeHttpObj = new JSONGet(mContext, url) { @SuppressWarnings("unchecked") @Override protected void jsonHandler(JSONObject routeJsonObj) { Log.i("Rota", "Rota recebida..."); try { // Qual o status da requisição da rota? String status = routeJsonObj.getString("status").toString(); // O webservice conseguiu traçar uma rota? if (status.equalsIgnoreCase("OK")) { Log.i("Rota", "Ok"); Log.i("overlay", mapOverlays.toString()); Log.i("overlay", mapOverlays.size()+""); // Remove a rota, caso exista if (mapOverlays.size() == 3) { mapOverlays.remove(2); } // Reseta o mapa itemizedOverlay.populateNow(); mapView.invalidate(); Log.i("overlay", mapOverlays.size()+""); // Extração da polyline codificada String polyline = routeJsonObj.getJSONArray("routes").getJSONObject(0).getJSONObject("overview_polyline").getString("points"); // Decodificação da polyline para um array de GeoPoints ArrayList&lt;GeoPoint&gt; route = RoadProvider.decodePolyline(polyline); // Instanciamento do objeto da rota RoadOverlay routeOverlay = new RoadOverlay(route); // Pega a lista de overlays e adiciona a rota ao mapview mapOverlays.add(routeOverlay); // Reseta o mapa itemizedOverlay.populateNow(); mapView.invalidate(); Log.i("overlay", mapOverlays.size()+""); Log.i("overlay", mapOverlays.toString()); // Pega os passos da rota /*JSONArray routeSteps = routeJsonObj.getJSONArray("routes").getJSONObject(0).getJSONObject("legs").getJSONArray("steps"); // Percorre os passos da rota e insere nos vetores, para guiar o motorista for (int i=0; i&lt;routeSteps.length(); i++) { // O objeto do passo no indice i JSONObject stepObj = routeSteps.getJSONObject(i); // Cria o array dos pontos GeoPoint[] arrPoints = new GeoPoint[2]; // Insere a latitude e longitude no array //arrPoints[0] = stepObj.getJSONObject(name) // Insere o array na lista routePoints.add(arrPoints); // routeInstructions }*/ // Copia os pontos para referencia futura routePoints = (ArrayList&lt;GeoPoint&gt;) route.clone(); } else { // Qual o erro? if (status.equalsIgnoreCase("NOT_FOUND")) { } else if (status.equalsIgnoreCase("ZERO_RESULTS")) { } else if (status.equalsIgnoreCase("MAX_WAYPOINTS_EXCEEDED")) { } else if (status.equalsIgnoreCase("INVALID_REQUEST")) { } else if (status.equalsIgnoreCase("OVER_QUERY_LIMIT") || status.equalsIgnoreCase("REQUEST_DENIED")) { } else { } } } catch (JSONException e) { e.printStackTrace(); } } }; // Desabilita a exibição do loading routeHttpObj.setDisplayDialog(false); // Executa a requisição routeHttpObj.execute(); } </code></pre> <p>Class which draws the route overlay</p> <pre><code>public class RoadOverlay extends Overlay { private ArrayList&lt;GeoPoint&gt; pointList; public RoadOverlay(ArrayList&lt;GeoPoint&gt; pointList) { this.pointList = pointList; } @Override public void draw(Canvas canvas, MapView mapView, boolean shadow) { Point current = new Point(); Path path = new Path(); Projection projection = mapView.getProjection(); Iterator&lt;GeoPoint&gt; iterator = pointList.iterator(); if (iterator.hasNext()) { projection.toPixels(iterator.next(), current); path.moveTo((float) current.x, (float) current.y); } else { return; } while(iterator.hasNext()) { projection.toPixels(iterator.next(), current); path.lineTo((float) current.x, (float) current.y); } Paint pathPaint = new Paint(); pathPaint.setAntiAlias(true); pathPaint.setStrokeWidth(8.0f); pathPaint.setColor(Color.argb(64, 0, 0, 255)); pathPaint.setStyle(Style.STROKE); canvas.drawPath(path, pathPaint); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload