如何在别人的顶部显示一个谷歌地图Android版标记? [英] How to display a Google Maps Android Marker on top of the others?

查看:137
本文介绍了如何在别人的顶部显示一个谷歌地图Android版标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序的多个标记,有时他们有些是在同一位置。我想其中的一些标志将始终显示在别人面前。我该如何操作?

I have multiple markers in my application, sometimes some of them are at the same position. I want some of those markers to be always displayed in front of the others. How should I proceed ?

感谢您提前。

推荐答案

我认为这是错误的做法。即使你把一个标记在对方面前还有一种可能性,即用户单击其后面的标记。

I think this is the wrong approach. Even if you put one marker in front of the other there is still a possibility that the user will click the marker that is behind.

我就不是这样做,就增加一个新的标记地图,检查是否已经有一个标记在新添加的标记的位置,如果是刚加入的新数据电流标记和不添加一个又一个。

I would instead of doing that, on adding a new Marker to the map, check if there is already a Marker at the newly added Marker location, if yes just added the new data to the current Marker and don't added another one.

这方式相同的标记将重新present同时指定位置。

that way the same marker will represent both specified locations.

更新:

看看这个code,在里面我检查,如果当前点击标记是我的当前位置。
而这样一来我知道我是否应该启动一个方向活动与否。您可以使用相同的工艺,以找出是否你已经在特定位置的标记。

Take a look at this code, in it I check if the currently clicked marker is my current location. And this way I know if I should fire up a directions activity or not. You can use the same technic to find out if you already have a marker at specific location.

 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;
                                    }
                                }
                                /*
                                findDirections(SGTasksListAppObj.getInstance().currentUserLocation.getLatitude(),
                                               SGTasksListAppObj.getInstance().currentUserLocation.getLongitude(),
                                               clickMarkerLatLng.latitude, clickMarkerLatLng.longitude, GMapV2Direction.MODE_DRIVING );
                                */
                                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;

            }
        });  

这篇关于如何在别人的顶部显示一个谷歌地图Android版标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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