一个对象标记(谷歌地图V2)关联 [英] Associate an object with Marker (google map v2)

查看:129
本文介绍了一个对象标记(谷歌地图V2)关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序我有自己的位置,显示使用的标记在地图上的某些对象。 问题是,我发现处理标记点击的唯一办法就是

In my app I have some objects that have their location displayed on the map using markers. The problem is that the only way I've found to handle marker clicks is

googleMap.setOnMarkerClickListener(new ... {
    @Override
    public void onMarkerClick(Marker marker) {
       // how to get the object associated to marker???
    }
})

在换句话说,我得到了标记的对象,而我拥有的唯一接口允许我仅有MarkerOptions。

In other words I get the Marker object while the only interface that I have allows me to set just MarkerOptions.

任何方式标记与对象相关联?

Any way to associate Marker with an object?

推荐答案

我觉得这个回调是不是很彻底,虽然由Android团队,但是,这是我们所拥有的。

I reckon this callback was not very thoroughly though by the Android team, but, it's what we have.

当你调用 mMap.addMarker(); 返回生成的标记。然后,您可以使用HashMap或其他数据的持有人结构,记住它。

Whenever you call mMap.addMarker(); it returns the generated marker. You can then use a HashMap or some other data holder structure to remember it.

// Create the hash map on the beginning
WeakHashMap <Marker, Object> haspMap = new WeakHashMap <Marker, Object>();


// whenever adding your marker
Marker m = mMap.addMarker(new MarkerOptions().position(lat, lng).title("Hello World").icon(icon_bmp));
haspMap.put(m, your_data);

这篇关于一个对象标记(谷歌地图V2)关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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