Issue
I have a MapActivity which has a touch event.
In the touch event:
I get the current geocodes
Put an overlay image on that location.
and set it as the center of the mapview.
This seems to work fine and as expected for a while. But then the application force closes. I think the touch event is being fired like crazy even when nothing's being touched. I know that because I had put a toast set up that shows the longitude and lattitude of the touched position. and it keeps showing up even when nothing's touched.
I cant seem to accurately position the problem, let alone fixing it. Here's the touch event for my mapActivity
private void LocationStuffs(double latitude, double longitude){
itemizedOverlay.clear();
itemizedOverlay.addOverlayItem((int)latitude, (int)longitude, "place");
mapView.invalidate();
mapView.getOverlays().add(itemizedOverlay);
MapController mc = mapView.getController();
mc.setCenter(new GeoPoint((int)latitude, (int)longitude));
mc.setZoom(20);
}
public boolean onTouchEvent(MotionEvent event, MapView mapView){
//---when user lifts his finger---
if (event.getAction() == 1) {
GeoPoint p = mapView.getProjection().fromPixels(
(int) event.getX(),
(int) event.getY());
Toast.makeText(getBaseContext(),
p.getLatitudeE6() / 1E6 + "," +
p.getLongitudeE6() /1E6 ,
Toast.LENGTH_SHORT).show();
latitude = p.getLatitudeE6() / 1E6;
longitude = p.getLongitudeE6() / 1E6;
LocationStuffs(latitude*1E6, longitude*1E6);
}
return false;
}
Solution
Change your return statement to return true:
return true;
Basically, what that does is that it tells the system that you have handled the touchevent. Let me know if that solves it.
Answered By - Vishwa Patel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.