如何选择使用地图V2的Andr​​oid API的一个标志?如何选择、标志、地图、Andr

由网友(无关回忆)分享简介:我目前正在使用的地图V1 API,它记录了什么标记(如果有的话)当前选择的 ItemizedOverlay 类。有没有类似的功能在地图V2,以确定哪些标志是当前选定的?此外,有没有一种方法以编程方式选择一个新的标记?I am currently using the ItemizedOverlay class from...

我目前正在使用的地图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();
}
阅读全文

相关推荐

最新文章