Getting coordinates when clicking anywhere on a MapView
Posted
by DixieFlatline
on Stack Overflow
See other posts from Stack Overflow
or by DixieFlatline
Published on 2010-05-07T08:30:21Z
Indexed on
2010/05/07
9:18 UTC
Read the original article
Hit count: 322
I just cant get this working. I tried using the code below with onTouchEventand and it doesn't work. If i return true at the end of the method, i get the toast with the coordinates but can't move a map, and if i return false, i can move a map but cant display a toast after the user clicks on a map. If i get it right, the other onTap method is used only for clicking on a overlays. Has anybody figured this thiing out?
public boolean onTouchEvent(MotionEvent arg0, MapView arg1) {
//super.onTouchEvent(arg0);
int akcija = arg0.getAction();
if(akcija == MotionEvent.ACTION_UP){
if(!premik) {
Projection proj = mapView.getProjection();
GeoPoint loc = proj.fromPixels((int)arg0.getX(), (int)arg0.getY());
String sirina=Double.toString(loc.getLongitudeE6()/1000000);
String dolzina=Double.toString(loc.getLatitudeE6()/1000000);
Toast toast = Toast.makeText(getApplicationContext(), "Širina: "+sirina+" Dolzina: "+dolzina, Toast.LENGTH_LONG);
toast.show();
}
}
else if (akcija == MotionEvent.ACTION_DOWN){
premik= false;
}
else if (akcija== MotionEvent.ACTION_MOVE){
premik = true;
}
return false;
//return super.onTouchEvent(arg0);
}
© Stack Overflow or respective owner