地图API V2具有不同的标志行动标志、不同、行动、地图

2023-09-04 03:01:35 作者:有你在的温暖

我想我的端口应用到新的谷歌地图API第2版,但我与标记交互时遇到了麻烦。

I'm trying to port my application to the new Google Maps API v2, but i'm having trouble when interacting with markers.

我的背景:我有一个显示公交车和公交车站的地图。随着旧的图书馆中,我有我自己的ItemizedOverlay的巴士站,另一个用于总线。每个人都有不同的OnTapListener(其实我使用一个外部库,以显示气球),这样当用户点击该总线标志没有任何反应,但是当他拿出巴士站的标记,其信息的行为被打开。此外,在我的ItemizedOverlay我映射每个标记与模型的公交车站对象。

My context: I have a map showing buses and buses stop. With the old library I had my own ItemizedOverlay for bus stops and another one for buses. Each one had a different OnTapListener (actually I use an external library to show balloons), so when the user taps the bus marker nothing happens, but when he taps the bus stop marker an activity with its information is opened. Also, in my ItemizedOverlay I mapped each marker with its bus stop object of the model.

现在使用新的API我有两个主要问题:

Now with the new API I have 2 main problems:

您设置一个侦听器setOnInfoWindowClickListener()或setOnMarkerClickListener()你的GoogleMap对象的方法。换句话说,你只能设置一个监听器为整个地图,所以我不能抽头之间的区别在公交车站或公交车。 这两个标记的onclick方法只能得到标记对象,从那里我不能得到太多信息,如公交车站数以打开其活动(我希望有一个比分析标题字符串更好的办法!O_O )

我觉得这两个问题可以通过标记不同的su​​bclases得到解决,但它没有构造函数和添加时,它的地图,你得到它的参考,所以我不知道这是否是可以使用自定义实现。

I think these two problems could be resolved using different subclases of Marker, but it has no constructor and you get its reference when adding it to the map, so I don't know if it's possible to use a custom implementation.

这个API是新的,所以没有关于类似的问题在网络上的信息。我一直在试图找出如何解决这个问题,但我什么也没得到。有谁知道一个可能的解决办法?

The API is new so there isn't much information on the web about similar problems. I've been trying to figure out how to solve this, but I got nothing. Does anyone know a possible solution to this?

感谢。

编辑:从我目前的应用程序的两种类型的标记图的屏幕截图:

A screenshot from my current application's map with two types of markers:

推荐答案

我遇到了这个问题为好。 我的解决办法是:

I have run into this problem as well. My solution was:

private Map<Marker, MyModel> markerMap = new HashMap<>();
private GoogleMap mMap;

private void doMarkers(){
    MarkerOptions opt = new MarkerOptions();
    //Fill out opt from MyModel
    Marker marker = mMap.addMarker(opt);
    markerMap.put(marker, myModel);
}

然后在OnMarkerClickListener回调,拉你出来的模型用点击的标记HashMap中的。 还有一种方法Marker.getId(),它由于某种原因,返回字符串。我不明白为什么当你做出标记,你不能指定一个int ID,或者你为什么不能访问标记对象将其添加到地图前。

and then in the OnMarkerClickListener callback, pull your model out of the HashMap using the clicked marker. There is also a method Marker.getId() which for some reason returns a string. I don't understand why you can't specify an int id when you make the marker, or why you can't access the marker object before you add it to the map.