I'm totally new to android development, I used osmdroid in creating an app for Android, I want to get a point by clicking on the map and I found this solution :
MapEventsReceiver mReceive = new MapEventsReceiver()
{
@Override
public boolean singleTapConfirmedHelper(GeoPoint p) {
Toast.makeText(getBaseContext(),p.getLatitude() + " - "+p.getLongitude(),Toast.LENGTH_LONG).show();
GeoPoint point = new GeoPoint(p.getLatitude(),p.getLongitude());
// This is the line i will explain in problem #2
Global_point = point;
return true;
}
@Override
public boolean longPressHelper(GeoPoint p) {
return false;
}
};
MapEventsOverlay OverlayEvents = new MapEventsOverlay(mReceive);
mapView.getOverlays().add(OverlayEvents);
by this page, and I put it in Onclick
function of a Button.
The problems are:
1- It (point receiving) Won't stop and it will run forever, How can I stop it when a GeoPoint got received?
2- The MapEventsReceiver is an Interface that should implement as it defined, so singleTapConfirmedHelper
function should return a Boolean, How can I return the GeoPoint that got received by clicking? I know I can define a Global variable and fill it in singleTapConfirmedHelper-function but I am asking if it is possible to change the Interface-function return value.
Ps: I know i can remove the map overlay by indexing:
mapView.getOverlays().add(0,OverlayEvents);
mapView.getOverlays().remove(0);
but I don't know where should I put it.
You should call some methot from singleTapConfirmedHelper. It's anonymous class so it can call methos of the class where it's created.
And later, somewhere in your Activity or Fragment: