i’m currently having trouble to add dynamicly a marquer on my mapview, certainly due to my lack in java knowledge 🙁
which parameter should i give to my canvas to make this work?
when i fee the coordinates, the map goes where i want but i have no maker
((Button)findViewById(R.id.goMap)).setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
mapView.invalidate();
// On récupère notre EditText
EditText UserName = ((EditText)findViewById(R.id.getLon));
EditText Password = ((EditText)findViewById(R.id.getLat));
// On garde la chaîne de caractères
_lat = UserName.getText().toString();
_long = Password.getText().toString();
latTest = Double.parseDouble(_lat)* 1E6;
longTest = Double.parseDouble(_long)* 1E6;
p3 = new GeoPoint(
(int) (latTest ),
(int) (longTest ));
//---add the marker---
Bitmap bmp3 = BitmapFactory.decodeResource(
getResources(), R.drawable.maps_position_marker);
Canvas canvas= new Canvas();
canvas.drawBitmap(bmp3, screenP3ts.x-15, screenP3ts.y-30, null);
mapView.getProjection().toPixels(p3, screenP3ts);
mapController.animateTo(p3);
mapController.setCenter(p3);
Toast.makeText(TheMap.this, "lat=" + latTest + " et " + "long= " + longTest, Toast.LENGTH_SHORT).show();
}
});
in my intial code, the overlay which has all good parametres it needs, is loaded in the onCreate () methode and it works fine but as i mentioned i can’t figure out how to add the marker in the onclick () methode. I know what i did is wrong but i don’t know how to do 🙁
thx in advance
You are drawing to the canvas using
screenP3tsbefore you actually transform the lat / lon into screen coordinates. You need this: