如何获取标记文本的点击事件 [英] How to get click event of the marker text

查看:78
本文介绍了如何获取标记文本的点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用中显示google map api v2。我在地图上设置了一些标记。
我也在标记上设置了标题和片段,当你点击标记时显示标记。



现在我想在点击标记的标题,而不是标记本身。

  map.setOnMarkerClickListner 

仅在点击标记时被调用。



但我不想这样做。我希望标记可以在标记点击时显示标题和片段,但是我想在点击标题时调用新活动。



任何想法我们如何做为了达到这个目的,你需要实现这个目标。

setOnInfoWindowClickListener 在您的 getInfoContents 方法中,以便点击您的 infoContents window会唤醒监听器做你想做的事情,你这样做:

  map.setInfoWindowAdapter(new InfoWindowAdapter() {

//使用默认的InfoWindow框架
@Override
public View getInfoWindow(Marker args){
return null;
}

//定义InfoWindow的内容
@Override
public View getInfoContents(Marker args){

//从布局文件中获取视图info_window_布局
查看v = getLayoutInflater()。inflate(R.layout.info_window_layout,null);

//从标记中获取位置
clickMarkerLatLng = args.getPosition();

TextView title =(TextView)v.findViewById(R.id.tvTitle);
title.setText(args.getTitle());

map.setOnInfoWindowClickListener(new OnInfoWindowClickListener(){
public void onInfoWindowClick(Marker marker)
{
if(SGTasksListAppObj.getInstance()。currentUserLocation!= null) (String.valueOf(SGTasksListAppObj.getInstance()。currentUserLocation.getLatitude())。substring(0,8).contains(String.valueOf(clickMarkerLatLng.latitude).substring(0, 8))&&
String.valueOf(SGTasksListAppObj.getInstance()。currentUserLocation.getLongitude())。substring(0,8).contains(String.valueOf(clickMarkerLatLng.longitude).substring(0, 8)))
{
Toast.makeText(getApplicationContext(),这是你的当前位置,不需要导航。,Toast.LENGTH_SHORT).show();
}
else
{
FlurryAgent.onEvent(从日常地图中点击开始导航窗口);
tasksRepository = SGTasksListAppObj.getInstance()。tasksRepository.getTasksRepository();
for(Task tmptask:tasksRepository)
{
String tempTaskLat = String.valueOf(tmptask.getLatitude());
String tempTaskLng = String.valueOf(tmptask.getLongtitude());

Log.d(TAG,String.valueOf(tmptask.getLatitude())+,+ String.valueOf(clickMarkerLatLng.latitude).substring(0,8));如果(tempTaskLat.contains(String.valueOf(clickMarkerLatLng.latitude).substring(0,8))&& tempTaskLng.contains(String.valueOf(clickMarkerLatLng.longitude).substring(0))

。 ,8)))
{
task = tmptask;
休息;
}
}

Intent intent = new Intent(getApplicationContext(),RoadDirectionsActivity.class);
intent.putExtra(TasksListActivity.KEY_ID,task.getId());
startActivity(intent);


$ b else

Toast.makeText(getApplicationContext(),你的当前位置找不到,\\\
Navigation不是可能。,Toast.LENGTH_SHORT).show();
}
}
});

//返回包含InfoWindow内容的视图
return v;

}
});


I am displaying google map api v2 in my app. I have set some markers in the map. I have also set title and snippet on the markers which are shown when you click the marker.

Now I want to call a new activity when clicked on the marker's title and not on marker itself.

map.setOnMarkerClickListner

is called only on the click of the marker.

But I dont want to do that. I want the marker to show the title and snippet on the click of the marker but I want to call new activity on the click of the title.

Any idea how we do that?

Thanks

解决方案

To achieve this you need to implement setOnInfoWindowClickListener in your getInfoContents method so that a click on your infoContents window will wake the listener to do what you want, you do it like so:

   map.setInfoWindowAdapter(new InfoWindowAdapter() {

            // Use default InfoWindow frame
            @Override
            public View getInfoWindow(Marker args) {
                return null;
            }

            // Defines the contents of the InfoWindow
            @Override
            public View getInfoContents(Marker args) {

                // Getting view from the layout file info_window_layout
                View v = getLayoutInflater().inflate(R.layout.info_window_layout, null);

                // Getting the position from the marker
                clickMarkerLatLng = args.getPosition();

                TextView title = (TextView) v.findViewById(R.id.tvTitle);
                title.setText(args.getTitle());

                map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {          
                    public void onInfoWindowClick(Marker marker) 
                    {
                        if (SGTasksListAppObj.getInstance().currentUserLocation!=null)
                        {   
                            if (String.valueOf(SGTasksListAppObj.getInstance().currentUserLocation.getLatitude()).substring(0, 8).contains(String.valueOf(clickMarkerLatLng.latitude).substring(0, 8)) &&
                                    String.valueOf(SGTasksListAppObj.getInstance().currentUserLocation.getLongitude()).substring(0, 8).contains(String.valueOf(clickMarkerLatLng.longitude).substring(0, 8)))
                            {
                                Toast.makeText(getApplicationContext(), "This your current location, navigation is not needed.",  Toast.LENGTH_SHORT).show();
                            }
                            else
                            {
                                FlurryAgent.onEvent("Start navigation window was clicked from daily map");
                                tasksRepository = SGTasksListAppObj.getInstance().tasksRepository.getTasksRepository();
                                for (Task tmptask : tasksRepository)
                                {
                                    String tempTaskLat = String.valueOf(tmptask.getLatitude());
                                    String tempTaskLng = String.valueOf(tmptask.getLongtitude());

                                    Log.d(TAG, String.valueOf(tmptask.getLatitude())+","+String.valueOf(clickMarkerLatLng.latitude).substring(0, 8));

                                    if (tempTaskLat.contains(String.valueOf(clickMarkerLatLng.latitude).substring(0, 8)) && tempTaskLng.contains(String.valueOf(clickMarkerLatLng.longitude).substring(0, 8)))
                                    {  
                                        task = tmptask;
                                        break;
                                    }
                                }

                                Intent intent = new Intent(getApplicationContext() ,RoadDirectionsActivity.class);
                                intent.putExtra(TasksListActivity.KEY_ID, task.getId());
                                startActivity(intent);

                            }
                        }
                        else
                        {
                            Toast.makeText(getApplicationContext(), "Your current location could not be found,\nNavigation is not possible.",  Toast.LENGTH_SHORT).show();
                        }
                    }
                });

                // Returning the view containing InfoWindow contents
                return v;

            }
        });  

这篇关于如何获取标记文本的点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆