有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何处理MapView的onClick事件并打开Google地图应用程序?

我的申请表中有一个MapView。我已经让它按我所希望的方式工作,但我想处理所有的onClickMapView的等效事件,并打开谷歌地图应用程序

我已经读到,我可以打开谷歌地图应用程序,但提出了如下Intent

String uri = "geo:"+ latitude + "," + longitude;
startActivity(new Intent(安卓.content.Intent.ACTION_VIEW, Uri.parse(uri)));

如何捕获myMapView的上述事件?我还没弄明白。谢谢


共 (2) 个答案

  1. # 1 楼答案

    您应该在活动中有一个扩展com.google.android.maps.Overlay的类,并使用这个类的onTouchEvent()方法。像这样:

    class MyOverlay extends Overlay {
    
        @Override
        public boolean onTouchEvent(MotionEvent e, MapView mapView) {
             ....
        }
        ....
    }
    
  2. # 2 楼答案

    我像这样使用了onTap事件:

    public boolean onTap(GeoPoint gptLocation, MapView mapMap) {
    
        String strCoordinates = String.format("%f,%f", gptCoordinates.getLatitudeE6() / 1E6, gptCoordinates.getLongitudeE6() / 1E6);
        String strUri = String.format("geo:%s?z=14", strCoordinates);
        Intent ittMap = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(strUri));
        ittMap.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        this.ctxContext.startActivity(ittMap);
        return false;
    
    }