vam*_*ibm 10 maps android markers
有没有办法通过android maps API,我可以在平移动画完成后检测地图中心?我想使用此信息动态地从服务器加载标记.谢谢BD
小智 12
我也一直在寻找一种"do end drag"解决方案,该解决方案在地图结束移动后恰好检测地图中心.我还没有找到它,所以我做了这个简单的实现,它做得很好:
private class MyMapView extends MapView {
private GeoPoint lastMapCenter;
private boolean isTouchEnded;
private boolean isFirstComputeScroll;
public MyMapView(Context context, String apiKey) {
super(context, apiKey);
this.lastMapCenter = new GeoPoint(0, 0);
this.isTouchEnded = false;
this.isFirstComputeScroll = true;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN)
this.isTouchEnded = false;
else if (event.getAction() == MotionEvent.ACTION_UP)
this.isTouchEnded = true;
else if (event.getAction() == MotionEvent.ACTION_MOVE)
this.isFirstComputeScroll = true;
return super.onTouchEvent(event);
}
@Override
public void computeScroll() {
super.computeScroll();
if (this.isTouchEnded &&
this.lastMapCenter.equals(this.getMapCenter()) &&
this.isFirstComputeScroll) {
// here you use this.getMapCenter() (e.g. call onEndDrag method)
this.isFirstComputeScroll = false;
}
else
this.lastMapCenter = this.getMapCenter();
}
}
Run Code Online (Sandbox Code Playgroud)
就是这样,我希望它有所帮助!O /
您使用的是吗MapActivity?这是我使用过的代码:
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;
Run Code Online (Sandbox Code Playgroud)
您确实还需要添加与此类似的代码:
@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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7236 次 |
| 最近记录: |