Hi. Is there a way through the android maps API, where I can detect the map center after pan animation has completed? I want to use this information to load markers from a server dynamically. Thanks BD
views:
864answers:
2
+2
A:
Are you using a MapActivity
? Here's the code I've used:
MapView mapView = (MapView)findViewById(R.id.map);
Projection projection = mapView.getProjection();
int y = mapView.getHeight() / 2;
int x = mapView.getWidth() / 2;
GeoPoint geoPoint = projection.fromPixels(x, y);
double centerLatitude = (double)geoPoint.getLatitudeE6() / (double)1E6;
double centerLongitude = (double)geoPoint.getLongitudeE6() / (double)1E6;
You do need to add code similar to this also:
@Override
public boolean dispatchTouchEvent(MotionEvent event)
{
boolean result = super.dispatchTouchEvent(event);
if (event.getAction() == MotionEvent.ACTION_UP)
reload_map_data(); /// call the first block of code here
return result;
}
marcc
2009-11-20 23:00:57
Does this handle the "fling" where the map keeps moving a little ways if you fling it (after you lift your finger)?
fiXedd
2009-11-21 04:41:20
Hi. thanks for the reply marcc, but i need to find a way to detect when the pan animation stops so that I can use your center calculation code at that point.
vamsibm
2009-11-25 19:18:05
A:
that solution above could have zoom control malfunction! It seems that the ev.getAction == MotionEvent.ACTION_UP could trigger the same function as zoom control, to make zoom out/in until reach the limit.
Could anyone help me out here? How could I distinguish between zoom control and the function above?? THX!~
Robert
2009-12-22 11:34:01