本文介绍了如何选择和取消的Andr​​oid在谷歌地图的标志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用标记标记在谷歌地图的地点列表。我想选择一个标记,这样它会用不同的颜色来突出显示。我一直在使用它设置<$c$c>marker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)).当我点击相同的标记或任何其他标​​记我想删除第一个标记所做的选择和设置恢复到默认的颜色。

I have a list of places which are marked in google maps using Markers. I want to select a Marker so that it will highlight with a different color. I have set it using marker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)). When I click on the same marker or any other marker I want remove the selection made in the first marker and set it back to the default color.

 map.setOnMarkerClickListener(new OnMarkerClickListener() {

    @Override
    public boolean onMarkerClick(Marker marker) {

        aa= marker.getPosition().latitude;
         bb=marker.getPosition().longitude;
        marker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));

        }

按照code以上时,我点击其他标记在第一标记中所做的选择仍然存在,而且保持颜色的 HUE_BLUE 。如何删除修改后的颜色和转移选择当前点击标记?

According to the code above when i click on other markers the selection made in the first marker is still there, and it stays colored HUE_BLUE. How can I remove the modified color and transfer the selection to currently clicked marker?

推荐答案

我只是测试这和它的作品,只是为了添加标记引用作为实例变量保持每一次一个新的标记点击,设置previous最后点击标记的参考,并一回默认的颜色。

I just tested this and it works, just add a Marker reference as an instance variable in order to keep a reference of the last clicked Marker, and each time a new Marker is clicked, set the previous one back to the default color.

您还可以检查!marker.equals(prevMarker)标记设置为前 HUE_BLUE ,这将允许在标记随后点击来设置颜色返回到默认的颜色。

You can also check !marker.equals(prevMarker) before setting the Marker to HUE_BLUE, this will allow a subsequent click on the Marker to set the color back to the default color.

实例变量:

Marker prevMarker;

点击监听器:

mGoogleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {

        @Override
        public boolean onMarkerClick(Marker marker) {

            aa= marker.getPosition().latitude;
            bb=marker.getPosition().longitude;
            if (prevMarker != null) {
                //Set prevMarker back to default color
                prevMarker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
            }

            //leave Marker default color if re-click current Marker
            if (!marker.equals(prevMarker)) {
                marker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
                prevMarker = marker;
            }
            prevMarker = marker;
            return false;
        }

    }); 

这篇关于如何选择和取消的Andr​​oid在谷歌地图的标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 04:15