如何选择使用地图V2的Andr​​oid API的一个标志? [英] How do I select a marker using the Maps V2 Android API?

查看:81
本文介绍了如何选择使用地图V2的Andr​​oid API的一个标志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用的地图V1 API,它记录了什么标记(如果有的话)当前选择的 ItemizedOverlay 类。有没有类似的功能在地图V2,以确定哪些标志是当前选定的?此外,有没有一种方法以编程方式选择一个新的标记?

I am currently using the ItemizedOverlay class from the Maps V1 API, which keeps track of what marker (if any) is currently selected. Is there any similar functionality in Maps V2 to determine which marker is currently selected? Also, is there a way to programatically select a new marker?

推荐答案

是的。

要确定选择哪个标记,OnInfoWindowClickedListener添加到您的GoogleMap的:

To determine which marker is selected, add a OnInfoWindowClickedListener to your GoogleMap:

//mMap is an instance of GoogleMap
mMap.setOnInfoWindowClickListener(getInfoWindowClickListener());

重写OnInfoWindowClickListener内的onInfoWindowClicked()方法:

Override the onInfoWindowClicked() method inside of the OnInfoWindowClickListener:

public OnInfoWindowClickListener getInfoWindowClickListener()
{
    return new OnInfoWindowClickListener() 
    {       
        @Override
        public void onInfoWindowClick(Marker marker) 
        {
            Toast.makeText(getApplicationContext(), "Clicked a window with title..." + marker.getTitle(), Toast.LENGTH_SHORT).show();
        }
    };      
}

和保持选定标记的轨道,也许实例变量。

And keep track of the selected marker, perhaps with an instance variable.

要以编程方式选择一个标志,你必须保持所有标记的​​列表,然后得到一个手柄之一,并呼吁showInfoWindow(),与此类似:

To select a marker programmatically, you'll have to keep a list of all your markers, then get a handle on one and call showInfoWindow(), similar to this:

//markerList is just a list keeping track of all the markers you've added
//to the map so far, which means you'll have to add each marker to this
//list as you put it on the map
Marker marker = this.markerList.get(someObjectYoureShowingAMarkerFor.getId());

if(marker != null)
{
    marker.showInfoWindow();
}

这篇关于如何选择使用地图V2的Andr​​oid API的一个标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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