即使移动了地图视图,onTap监听器如何在android地图视图中工作。 实际上我是根据用户指示旋转地图视图。
我正从sesor经理那里获得承受角度。
如果角度为0,则onTap在Pin上正常工作。如果角度改变,则说20 onTap不能正确地在引脚上工作,它会在一些空间后在引脚旁边工作。
我采用了旋转视图,我采用的是mapview。现在,在轴承更改后旋转旋转视图。
RotateView设置轴承代码
@Override
protected void dispatchDraw(Canvas canvas) {
canvas.save(Canvas.MATRIX_SAVE_FLAG);
//if mHeading is zero its work otherwise onTap position is changing
canvas.rotate(mHeading, getWidth()/2, getHeight());
mCanvas.delegate = canvas;
super.dispatchDraw(mCanvas);
canvas.restore();
}
重叠课程
public class SonarOverlay1 extends ItemizedOverlay<OverlayItem>
{
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private Context mContext;
public SonarOverlay1(Drawable defaultMarker,Context context) {
super(boundCenter(defaultMarker));
this.mContext=context;
populate();
}
@Override
protected OverlayItem createItem(int arg0) {
return mOverlays.get(arg0);
}
public void addOverlay(OverlayItem item) {
mOverlays.add(item);
populate();
}
@Override
public int size() {
//Log.e("overlay size..",""+mOverlays.size());
return mOverlays.size();
}
@Override
protected boolean onTap(int index) {
// TODO Auto-generated method stub
OverlayItem item = mOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}
}
答案 0 :(得分:1)
查看
中的MapsDemo示例ANDROID_SDK \插件\插件-google_apis-google_inc_-7 \样品\ MapsDemo。
它有旋转地图演示。
旋转MapView的最简单方法
感谢。
答案 1 :(得分:1)
在旋转地图的同时,我们必须使用onDispatchTouch方法旋转触摸evnts以及地图
见下面的代码
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
float[] coords = new float[] {
event.getX(), event.getY()
};
adjustCoords(coords, getRotation());
MotionEvent evt = MotionEvent.obtain(event.getDownTime(), event.getEventTime(), event
.getAction(), coords[0], coords[1], event.getPressure(), event.getSize(), event
.getMetaState(), event.getXPrecision(), event.getYPrecision(), event.getDeviceId(),
event.getEdgeFlags());
return super.dispatchTouchEvent(evt);
}
protected void adjustCoords(float[] coords, float deg) {
float x = coords[0];
float y = coords[1];
int centerX = getWidth() / 2;
int centerY = getHeight() / 2;
// convert to radians
float rad = (float) ((deg * Math.PI) / 180F);
float s = (float) Math.sin(rad);
float c = (float) Math.cos(rad);
// translate point back to origin:
x -= centerX;
y -= centerY;
// apply rotation
float tmpX = x * c - y * s;
float tmpY = x * s + y * c;
x = tmpX;
y = tmpY;
// translate point back:
x += centerX;
y += centerY;
coords[0] = x;
coords[1] = y;
}
请参阅以下链接
How to manage overlays in MapViewCompassDemo in android sdk samples