【问题标题】:Define a clickable/touchable area for custom markers in android google-maps-api-2在 android google-maps-api-2 中为自定义标记定义可点击/可触摸区域
【发布时间】:2018-07-03 18:51:12
【问题描述】:

我是 google 地图或者更确切地说是 android 编程的新手。尽管如此,我还是设法为互联网浏览器设置了谷歌地图。我创建了几个具有特定可点击区域的自定义标记(带有我自己图标的标记)。

对于互联网浏览器的谷歌地图,这个下降

      var shape = {
      coords: [1, 1, 1, 20, 18, 20, 18, 1],
      type: 'poly'
    };
    for (var i = 0; i < beaches.length; i++) {
      var beach = beaches[i];
      var marker = new google.maps.Marker({
        position: {lat: beach[1], lng: beach[2]},
        map: map,
        icon: image,
        shape: shape,
        title: beach[0],
        zIndex: beach[3]
      });
    }

因此,您定义了一个形状,该形状将成为标记的可点击区域。这行得通。

现在我喜欢为安卓设备开发我的谷歌地图应用程序。我想要与我在浏览器的谷歌地图中使用的相同的标记图标。虽然这不是像以前那样用 JavaScript 编写的,而是用 Java 编写的,而且我已经完成了。但是我无法找到一个选项来为我在 android 谷歌地图上的自定义标记创建可点击或可触摸的区域!我的自定义图标周围甚至有很大的区域,我无法更改它。

那么你知道我可以如何为 android 的谷歌地图标记定义可点击/可触摸区域的选项吗? 还是因为拇指不像电脑鼠标那样准确,所以不可能?

Screenshot of my map with the problem

诚挚的问候, 任务管理器

【问题讨论】:

    标签: android google-maps google-maps-markers google-maps-android-api-2 clickable


    【解决方案1】:

    您需要注册OnInfoWindowClickListenerCallbackGoogleMap 中有一个方法:

    map.setOnInfoWindowClickListener(new OnInfoWindowClickListener()
            {
                @Override
                public void onInfoWindowClick(Marker arg0) {
                    //Handle your click here                
            }
            }); 
    

    更新:

    // Set a listener for marker click.    
    mMap.setOnMarkerClickListener(this);
    
    /** Called when the user clicks a marker. */
    @Override
    public boolean onMarkerClick(final Marker marker) {
    
        // Retrieve the data from the marker.
        Integer clickCount = (Integer) marker.getTag();
    
        // Check if a click count was set, then display the click count.
        if (clickCount != null) {
            clickCount = clickCount + 1;
            marker.setTag(clickCount);
            Toast.makeText(this,
                           marker.getTitle() +
                           " has been clicked " + clickCount + " times.",
                           Toast.LENGTH_SHORT).show();
        }
    
        // Return false to indicate that we have not consumed the event and that we wish
        // for the default behavior to occur (which is for the camera to move such that the
        // marker is centered and for the marker's info window to open, if it has one).
        return false;
    }
    

    请参阅Markers 了解更多详情。还要确保您用于标记的图像中没有填充。

    【讨论】:

    • 感谢您的回复。我没有任何信息窗口,因为我只需要标记本身。标记已经是可点击的,我有一个 clicklistener 可以按需要工作。问题是我无法像浏览器版本上的形状那样减小标记的可点击/可触摸区域的大小。可点击区域太大。 Please see my screenshotRgds,任务管理器
    猜你喜欢
    • 2013-03-29
    • 1970-01-01
    • 2014-02-25
    • 1970-01-01
    • 1970-01-01
    • 2011-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多