在地图不同的标记区分API V2(唯一标识符) [英] Differentiate between different markers in Maps API v2 (unique identifiers)

查看:163
本文介绍了在地图不同的标记区分API V2(唯一标识符)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义类的ArrayList。有列表中的约10个对象,每个像标题,摘录,经纬度信息。我已经成功地通过使用类似的getTitle,getSnippet,getLatLng等我的自定义类的功能添加的所有10到地图。

I have an ArrayList of a custom class. There are about 10 objects in the list, each with details like Title, Snippet, LatLng. I have successfully added all 10 to a Map by using my custom class functions like getTitle, getSnippet, getLatLng etc.

现在,当我点击信息窗口(的标记),我希望能够以某种方式知道我的自定义类的对象,这是否标记对应。

Now, when I click the info window (of the marker), I want to be able to somehow KNOW which object of my custom class does that marker correspond to.

例如,如果我点击麦当劳的市场,我希望能够知道哪些项目从我的ArrayList这样做标记属于

For example, if I click the McDonald's market, I want to be able to know which item from my ArrayList did that marker belong to.

我一直在寻找的MarkerOptions而且似乎没有任何东西在那里,我可以用它来识别相关的自定义对象。

I've been looking at the MarkerOptions and there doesn't seem to be anything in there that I can use to identify the relevant custom object with.

如果问题是太混乱了,让我简单:

If the question is too confusing, let me make it simple:

ArrayList<CustomObj> objects = blah
map.addMarker(new MarkerOptions().position(new LatLng(
                            Double.parseDouble(result.get(i).getCompanyLatLng()
                                    .split(",")[0]), Double.parseDouble(result
                                    .get(i).getCompanyLatLng().split(",")[1])))
                                    .title(result.get(i).getCompanyName())
                                    .snippet(result.get(i).getCompanyType())
                                    .icon(BitmapDescriptorFactory
                                            .fromResource(R.drawable.pin)));

现在,当这个被点击,我去到下一个页面。下一个页面需要知道哪个对象被点击,这样我可以把其他的细节,该页面(这需要加载等如图像的URL)。

Now when this is clicked, I go on to the next page. The next page needs to know WHICH object was clicked so that I can send the other details to that page (e.g. Image URLs that need to be loaded etc).

我如何添加到我的标记一个唯一的整数或标识符?

How do I add a unique integer or any identifier to my marker?

推荐答案

一个正确的方法是使用地图&LT;标记,CustomObj&GT; 存储所有标志物:

One correct way is to use Map<Marker, CustomObj> which stores all markers:

Marker marker = map.addMarker(...);
map.put(marker, result.get(i));

onInfoWindowClick

CustomObj obj = map.get(marker);

另一次尝试使用 Android地图扩展的,里面加的getData 使用setData 方法标记,这样你就可以将你的 CustomObj 对象之后创建的标记,并在任何回调检索。

Another try is using Android Maps Extensions, which add getData and setData method to Marker, so you can assign your CustomObj object after creating marker and retrieve it in any callback.

这篇关于在地图不同的标记区分API V2(唯一标识符)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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