Android 我怎样才能把“我”写进去;“各种各样的”;谷歌地图上的click Listener实例?

Android 我怎样才能把“我”写进去;“各种各样的”;谷歌地图上的click Listener实例?,android,google-maps,Android,Google Maps,我在地图上画了很多圆圈,我希望这些圆圈有自己的OncircleClick监听器 但问题是,我只能在谷歌地图上注册一个圈点击监听器,而这个监听器是每个圈共享的,所以每次我点击任何圈,都会发生相同的监听器事件 你能让我知道如何使每个圆圈都能有自己的圆圈点击监听器吗?多谢各位 这是我的代码: private void drawCircle(LatLng point, boolean isOverThreshold, final Bundle results){ GoogleMap.

我在地图上画了很多圆圈,我希望这些圆圈有自己的OncircleClick监听器

但问题是,我只能在谷歌地图上注册一个圈点击监听器,而这个监听器是每个圈共享的,所以每次我点击任何圈,都会发生相同的监听器事件

你能让我知道如何使每个圆圈都能有自己的圆圈点击监听器吗?多谢各位

这是我的代码:

 private void drawCircle(LatLng point, boolean isOverThreshold, final Bundle results){

        GoogleMap.OnCircleClickListener onCircleClickListener = new GoogleMap.OnCircleClickListener() {
            @Override
            public void onCircleClick(Circle circle) {

                int sixty_one = results.getInt("60hz_1");
                int eighty_one = results.getInt("180hz_1");
                int sixty_two = results.getInt("60hz_2");
                int eighty_two = results.getInt("180hz_2");
                int sixty_three = results.getInt("60hz_3");
                int eighty_three = results.getInt("180hz_3");
                double speed = results.getDouble("speed");
                Toast.makeText(ReplayActivity.this, "CH1: ("+sixty_one+","+eighty_one+") \n"+" CH2: (" + sixty_two+","+eighty_two+") \n" + "CH3: ("+sixty_three+","+eighty_three+")\n speed:"+speed+"m/s )",Toast.LENGTH_SHORT).show();

                Log.d("gd","circle clicked!");
            }
        };

        // Instantiating CircleOptions to draw a circle around the marker
        CircleOptions circleOptions = new CircleOptions();

        // Specifying the center of the circle
        circleOptions.center(point);

        (....)


        // Adding the circle to the GoogleMap
        map.addCircle(circleOptions);
        map.setOnCircleClickListener(onCircleClickListener); 
//but this oncircleListener is shared by every circle click event..
    }



您可以使用created circle object的方法来设置,例如将circle object(或更复杂结构)的ID设置为标记,然后在您的内部使用
onCircleClickListener
来获取此ID(或更复杂结构)。诸如此类:

private void drawCircle(LatLng point, boolean isOverThreshold, final Bundle results){

    GoogleMap.OnCircleClickListener onCircleClickListener = new GoogleMap.OnCircleClickListener() {
        @Override
        public void onCircleClick(Circle circle) {

            // get stored Tag object from passed circle object
            YOUR_TAG_OBJECT_CLASS yourTagObjectName = (YOUR_TAG_OBJECT_CLASS)circle.getTag();
            if (yourTagObjectName != null) {
                // parse it
                switch (yourTagObjectName.id) {
                    case ID_1: ... break;
                    case ID_2: ... break; 
                    ...
                }
             }

            int sixty_one = results.getInt("60hz_1");
            int eighty_one = results.getInt("180hz_1");
            int sixty_two = results.getInt("60hz_2");
            int eighty_two = results.getInt("180hz_2");
            int sixty_three = results.getInt("60hz_3");
            int eighty_three = results.getInt("180hz_3");
            double speed = results.getDouble("speed");
            Toast.makeText(ReplayActivity.this, "CH1: ("+sixty_one+","+eighty_one+") \n"+" CH2: (" + sixty_two+","+eighty_two+") \n" + "CH3: ("+sixty_three+","+eighty_three+")\n speed:"+speed+"m/s )",Toast.LENGTH_SHORT).show();

            Log.d("gd","circle clicked!");
        }
    };

    // Instantiating CircleOptions to draw a circle around the marker
    CircleOptions circleOptions = new CircleOptions();

    // Specifying the center of the circle
    circleOptions.center(point);

    (....)


    // Adding the circle to the GoogleMap
    Circle circle = map.addCircle(circleOptions);  // <- store circle object
    circle.setTag(YOUR_TAG_ID_OR_OBJECT);          // <- set Tag to stored circle object

    map.setOnCircleClickListener(onCircleClickListener); 
}
private void drawCircle(LatLng点、布尔值isOverThreshold、最终捆绑结果){
GoogleMap.OnCircleClickListener OnCircleClickListener=新建GoogleMap.OnCircleClickListener(){
@凌驾
圆形单击上的公共空白(圆形){
//从传递的圆对象获取存储的标记对象
你的标记对象类你的标记对象名=(你的标记对象类)circle.getTag();
if(yourTagObjectName!=null){
//解析它
开关(yourTagObjectName.id){
案例ID_1:…中断;
案例ID_2:…中断;
...
}
}
int六十_一=results.getInt(“60hz_一”);
int八十一=results.getInt(“180hz_1”);
int六十二=results.getInt(“60hz_2”);
int八十二=results.getInt(“180hz_2”);
int-sixture_-three=results.getInt(“60hz_-3”);
int八十三=results.getInt(“180hz_3”);
双速=结果。getDouble(“速度”);
Toast.makeText(ReplayActivity.this,“CH1:(“+Sixtheu-one+”,“+八十一+”)\n“+”CH2:(“+Sixtheu-Du+”,“+八十二+”)\n“+”CH3:(“+Sixtheu-three+”,“+八十三+”)\n速度:“+speed+”m/s)”,Toast.LENGTH\u show();
Log.d(“gd”,“点击圆圈!”);
}
};
//实例化CircleOptions以围绕标记绘制圆
CircleOptions CircleOptions=新的CircleOptions();
//指定圆的中心
圆圈。中心(点);
(....)
//将圆添加到谷歌地图
Circle Circle=map.addCircle(circleOptions);//您可以使用创建的Circle对象的方法来设置,例如将Circle对象(或更复杂结构)的ID设置为标记,然后在您的
onCircleClickListener
中使用来获取此ID(或更复杂结构)。类似于:

private void drawCircle(LatLng point, boolean isOverThreshold, final Bundle results){

    GoogleMap.OnCircleClickListener onCircleClickListener = new GoogleMap.OnCircleClickListener() {
        @Override
        public void onCircleClick(Circle circle) {

            // get stored Tag object from passed circle object
            YOUR_TAG_OBJECT_CLASS yourTagObjectName = (YOUR_TAG_OBJECT_CLASS)circle.getTag();
            if (yourTagObjectName != null) {
                // parse it
                switch (yourTagObjectName.id) {
                    case ID_1: ... break;
                    case ID_2: ... break; 
                    ...
                }
             }

            int sixty_one = results.getInt("60hz_1");
            int eighty_one = results.getInt("180hz_1");
            int sixty_two = results.getInt("60hz_2");
            int eighty_two = results.getInt("180hz_2");
            int sixty_three = results.getInt("60hz_3");
            int eighty_three = results.getInt("180hz_3");
            double speed = results.getDouble("speed");
            Toast.makeText(ReplayActivity.this, "CH1: ("+sixty_one+","+eighty_one+") \n"+" CH2: (" + sixty_two+","+eighty_two+") \n" + "CH3: ("+sixty_three+","+eighty_three+")\n speed:"+speed+"m/s )",Toast.LENGTH_SHORT).show();

            Log.d("gd","circle clicked!");
        }
    };

    // Instantiating CircleOptions to draw a circle around the marker
    CircleOptions circleOptions = new CircleOptions();

    // Specifying the center of the circle
    circleOptions.center(point);

    (....)


    // Adding the circle to the GoogleMap
    Circle circle = map.addCircle(circleOptions);  // <- store circle object
    circle.setTag(YOUR_TAG_ID_OR_OBJECT);          // <- set Tag to stored circle object

    map.setOnCircleClickListener(onCircleClickListener); 
}
private void drawCircle(LatLng点、布尔值isOverThreshold、最终捆绑结果){
GoogleMap.OnCircleClickListener OnCircleClickListener=新建GoogleMap.OnCircleClickListener(){
@凌驾
圆形单击上的公共空白(圆形){
//从传递的圆对象获取存储的标记对象
你的标记对象类你的标记对象名=(你的标记对象类)circle.getTag();
if(yourTagObjectName!=null){
//解析它
开关(yourTagObjectName.id){
案例ID_1:…中断;
案例ID_2:…中断;
...
}
}
int六十_一=results.getInt(“60hz_一”);
int八十一=results.getInt(“180hz_1”);
int六十二=results.getInt(“60hz_2”);
int八十二=results.getInt(“180hz_2”);
int-sixture_-three=results.getInt(“60hz_-3”);
int八十三=results.getInt(“180hz_3”);
双速=结果。getDouble(“速度”);
Toast.makeText(ReplayActivity.this,“CH1:(“+Sixtheu-one+”,“+八十一+”)\n“+”CH2:(“+Sixtheu-Du+”,“+八十二+”)\n“+”CH3:(“+Sixtheu-three+”,“+八十三+”)\n速度:“+speed+”m/s)”,Toast.LENGTH\u show();
Log.d(“gd”,“点击圆圈!”);
}
};
//实例化CircleOptions以围绕标记绘制圆
CircleOptions CircleOptions=新的CircleOptions();
//指定圆的中心
圆圈。中心(点);
(....)
//将圆添加到谷歌地图
圆圈=map.addCircle(圆圈选项)//