Suprapunerile nu apar pe MapView

Așadar, mi-am făcut viziunea de hartă și totul se desfășoară, dar suprapunerile nu apar pe hartă. Orice sugestii sau ajutor la toate ar fi foarte apreciate. Clasa extensiei mele MapActivity este următoarea:

public class trailInformation extends MapActivity {
public String trailName = "";
public loadMapDataTask mapTask = new loadMapDataTask();
public myObject inp = new myObject();

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.trail_info_layout);

   //General variable declarations
    Intent intent = getIntent();
    trailName = intent.getStringExtra(trailsActivity.EXTRA_MESSAGE);

   //Sets map to satellite
    final MapView map = (MapView) findViewById(R.id.infoMapView);
    map.setSatellite(true);

   //Setup map input
    inp.setID(R.raw.nordhoff_peak_loop);
    inp.setName("mapfile");
    inp.setMap(map);

   //Display Trail Name
    Typeface font = Typeface.createFromAsset(getAssets(), "arial.ttf");
    TextView trailNameTV = (TextView) findViewById(R.id.infoTitle);
    trailNameTV.setText(trailName);
    trailNameTV.setTypeface(font);
    Display display = getWindowManager().getDefaultDisplay();
    trailNameTV.setTextSize(findTextSize(trailNameTV, trailName,
            GalleryPageActivity.getDisplaySize(display).x, font));
}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    mapTask.execute(inp);
}

public class loadMapDataTask extends AsyncTask {

    @Override
    protected File doInBackground(myObject... params) {
        File file = getApplicationContext().getFileStreamPath(
                params[0].getName());
        if (file.exists()) {
            return file;
        }

        InputStream is;
        FileOutputStream fos;
        try {
            is = getResources().openRawResource(params[0].getID());
            byte[] buffer = new byte[is.available()];
            is.read(buffer);
            fos = openFileOutput(params[0].getName(), MODE_PRIVATE);
            fos.write(buffer);
            fos.close();
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        List gpsPoints = XMLParser.getPoints(file);

        int i = 0;
        int index = 0;

        GeoPoint[] geoPoints = new GeoPoint[gpsPoints.size()];

        ListIterator it = gpsPoints.listIterator();
        while (it.hasNext()) {
            index = it.nextIndex();
            Location loc = gpsPoints.get(index);
            geoPoints[i] = new GeoPoint((int) (loc.getLatitude() * 1E6),
                    (int) (loc.getLongitude() * 1E6));
            it.next();
            Log.i("DEBUG", "" + geoPoints[i]);
        }
        if (geoPoints.length > 1) {
            mapOverlay[] overlays = new mapOverlay[(geoPoints.length - 1)];
            MapController mc = params[0].getMap().getController();
            mc.animateTo(geoPoints[0]);
            mc.setZoom(17);

            for (int z = 0; z < overlays.length; z++) {
                List mapOverlays;
                mapOverlays = params[0].getMap().getOverlays();
                mapOverlays.add(overlays[z]);
            }

        } else {
            Log.i("DEBUG", "Not drawing lines because " + geoPoints.length
                    + " points exist in geopoints array.");
        }
        return file;
    }

    @Override
    protected void onPostExecute(File result) {
        Log.i("DEBUG", "Task executed");
    }
}

public static String readRawTextFile(Context ctx, int resId) {
    InputStream inputStream = ctx.getResources().openRawResource(resId);

    InputStreamReader inputreader = new InputStreamReader(inputStream);
    BufferedReader buffreader = new BufferedReader(inputreader);
    String line;
    StringBuilder text = new StringBuilder();

    try {
        while ((line = buffreader.readLine()) != null) {
            text.append(line);
            text.append('\n');
        }
    } catch (IOException e) {
        return null;
    }
    return text.toString();
}

public float findTextSize(TextView tV, String text, float Width,
        Typeface font) {
    float textSize = 100;
    float scaledPx = 0;
    float densityMultiplier = getBaseContext().getResources()
            .getDisplayMetrics().density;
    TextPaint paint = tV.getPaint();
    paint.setTypeface(font);
    while (textSize > 20) {
        scaledPx = textSize * densityMultiplier;
        paint.setTextSize(scaledPx);
        if (paint.measureText(text) < Width) {
            return textSize;
        } else {
            textSize--;
        }
    }
    return 0;
}

@Override
protected boolean isRouteDisplayed() {
   //TODO Auto-generated method stub
    return false;
}
}

Și clasa mea mapOverlay este următoarea:

public class mapOverlay extends Overlay {

private Projection projection;

public mapOverlay(MapView map) {
    super();
    projection = map.getProjection();
}

public void draw(Canvas canvas, MapView mapv, boolean shadow, GeoPoint gp1,
        GeoPoint gp2) {
    super.draw(canvas, mapv, shadow);

   //Configuring the paint brush
    Paint mPaint = new Paint();
    mPaint.setDither(true);
    mPaint.setColor(Color.RED);
    mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeCap(Paint.Cap.ROUND);
    mPaint.setStrokeWidth(4);

    Point p1 = new Point();
    Point p2 = new Point();
    Path path1 = new Path();

    projection.toPixels(gp1, p1);
    projection.toPixels(gp2, p2);

    path1.moveTo(p1.x, p1.y);
    path1.lineTo(p2.x, p2.y);

    canvas.drawPath(path1, mPaint);
}

}

Cred că mi-ar lipsi ceva despre MapView și poate exista și o problemă cu Asynctask-ul meu de când este prima dată când îl folosesc, dar nu cred că există.

0
Am facut. Am scris geointele la Logcat pentru a testa asta și se pare că sunt.
adăugat autor Brian Ecker, sursa
Verificați dacă coordonatele geografice corecte sunt transmise suprapunerilor
adăugat autor Orlymee, sursa
Android dezvoltatori, România — Moldova
Android dezvoltatori, România — Moldova
27 participanți

Parteneri: ciupacabra.com, @php_ro, @js_ro, @node_ro iOS: @ro_ios Reguli: https://github.com/js-ro/it-telegram/blob/master/RULES.md