【问题标题】:Android set Listener for marker on google mapAndroid为谷歌地图上的标记设置监听器
【发布时间】:2011-07-29 08:29:07
【问题描述】:

这是我在 Google 地图中使用的覆盖类。我向它添加了两个标记,并希望为这些标记添加一个侦听器。下面是我的覆盖类:

protected class MyLocationOverlay extends com.google.android.maps.Overlay {

    @Override
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {


        super.draw(canvas, mapView, shadow);
        // Converts lat/lng-Point to OUR coordinates on the screen.
        Point myScreenCoords = new Point();
        mapView.getProjection().toPixels(p, myScreenCoords);



        Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.passenger_map);

        canvas.drawBitmap(bmp, myScreenCoords.x, myScreenCoords.y, null);
        // canvas.drawText("I am here...", myScreenCoords.x, myScreenCoords.y, paint);

        mapView.getProjection().toPixels(p1, myScreenCoords);
        Bitmap bmp1 = BitmapFactory.decodeResource(getResources(), R.drawable.driver_map);

        canvas.drawBitmap(bmp1, myScreenCoords.x, myScreenCoords.y, null);
        // canvas.drawText(" Driver : I am here...", myScreenCoords.x, myScreenCoords.y, paint);
        return true;    
    }

【问题讨论】:

    标签: android android-maps


    【解决方案1】:

    您需要使用 ItemizedOverlay 类来点击标记。因为你需要覆盖

    onTap() 或 onTouch()

    既可用于标记,也可用于地图

    public boolean onTap (final GeoPoint p, final MapView mapView){
    boolean tapped = super.onTap(p, mapView);
    if (tapped){            
        //do what you want to do when you hit an item           
    }           
    else{
        //do what you want to do when you DONT hit an item
        }                   
    return true;
    

    }

    //你必须有这个方法,即使它没有明显做任何事情

    @覆盖 受保护的布尔 onTap(int index) { 返回真; }

    这里是链接

    http://developer.android.com/guide/tutorials/views/hello-mapview.html

    OnTap() event on map is not fired

    Android: ItemizedOverlay onTouchEvent and onTap overlapping

    Show popup above map marker in MapView

    【讨论】:

      猜你喜欢
      • 2014-05-10
      • 1970-01-01
      • 2019-02-09
      • 1970-01-01
      • 2019-09-23
      • 2016-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多