0

I am stuck with this, I have tried every possibility but not success. I have create simple application with map for testing and user can simple touch on map and on that place put the marker. This will work successfully in all device except in htc devices. I don't know how to implement onTouch event for mapview

here is my code for onTouch

private class MarkerOverlay extends Overlay{        
    private boolean isMove;
    @Override
    public boolean onTouchEvent(MotionEvent e, MapView mapView) {           
        final int x = (int) e.getX();
        final int y = (int) e.getY();
        if(e.getAction()==1){
            if(!isMove){
                geopoint = mapView.getProjection().fromPixels(x, y);
                OverlayItem overlayItem = new OverlayItem(geopoint, "Title", "Description");
                if(mapOverlay.m_overlays.size()>=1){
                    mapOverlay.clearOverlayAll();
                }
                mapOverlay.addOverlay(overlayItem);
                if(!mapView.getOverlays().contains(mapOverlay))
                    mapView.getOverlays().add(mapOverlay);

                mapView.invalidate();
                Toast.makeText(SimpleMapMarkerActivity.this, "in press", Toast.LENGTH_SHORT).show();
            }else{
                Toast.makeText(SimpleMapMarkerActivity.this, "out press", Toast.LENGTH_SHORT).show();
            }
        }else if(e.getAction()==MotionEvent.ACTION_DOWN)
            isMove = false;
        else if(e.getAction()==MotionEvent.ACTION_MOVE)
            isMove = true;

        return super.onTouchEvent(e, mapView);
    }
}
4

3 回答 3

0

地图标记示例

此示例向您展示如何在地图上绘制可移动标记。您可以拖放标记以更改其位置。可用于您希望从用户那里获取地图位置输入的任何应用程序。

算法:

1.) 通过 File-> New -> Android Project 创建一个新项目,将其命名为 MapMarkerExample。2.) 您将在 main.xml 和 android 清单文件中看到一些默认代码。3.) 将互联网权限添加到您的清单文件或在 android.manifest 文件中写入以下内容:

http://www.edumobile.org/android/android-apps/mapmarkerexample/

于 2011-12-30T09:24:22.470 回答
0

我得到了解决方案,这个解决方案由harism给出

每当您使用地图实施标记时,就像点击地图并显示市场一样,然后实施onTap(GeoPoint g, MapView mapview).

如果你想实现标记,比如像拖放一样由用户移动,那么使用onTouch(). 对于onTouch()和移动标记,如拖放检查此链接

http://www.edumobile.org/android/android-apps/mapmarkerexample/

于 2012-01-02T11:33:31.120 回答
0

我有同样的问题。我不确定它是否可以解决您的HTC问题。但这就是我所做的:

我已经覆盖了 dispatchTouchEvent。它适用于我的三星 Galaxy s2。

    @Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    // TODO Auto-generated method stub
    if(ev.getAction() == MotionEvent.ACTION_DOWN){
        xPos = ev.getX();
        yPos = ev.getY();
    }
    if (ev.getAction() == MotionEvent.ACTION_UP){
        if (xPos==ev.getX() && yPos == ev.getY()){
        Log.i(LOG_TAG, "Calling onTouch from dispatchTouchEvent.");
            onTouch(mapView, ev);
        }
    }
    return super.dispatchTouchEvent(ev);
}

我在 mapActivity 中做这个。不在overLay中。

于 2011-12-30T08:55:22.377 回答