在谷歌地图Android的V2自定义信息窗口 [英] Custom infowindow in Google map android v2

查看:856
本文介绍了在谷歌地图Android的V2自定义信息窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用谷歌地图API V2和我创建了一个自定义的信息窗口标记上map.In这个信息窗口我有一个按钮。

我的问题是无法设置Onclicklistener /功能给该按钮(假)。任何人给我一些想法解决这个问题:

下面是code片断:

 公共类MarkerView扩展FragmentActivity实现OnMarkerClickListener,OnInfoWindowClickListener {

私人GoogleMap的MMAP;
私人标记奈;
私人查看信息窗口;
@覆盖
保护无效的onCreate(捆绑为arg0){
    super.onCreate(为arg0);
    的setContentView(R.layout.basic_demo);

    信息窗口= getLayoutInflater()膨胀(R.layout.custom_info_contents,空)。

    MMAP =((SupportMapFragment)getSupportFragmentManager()findFragmentById(R.id.map)。)的GetMap()。
    奈= mMap.addMarker(新MarkerOptions()。位置(新的经纬度(13.0810,80.274))。锚(2, 1).title("Android").snippet("Snippet").icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));
    mMap.setInfoWindowAdapter(新CustomInfoAdapter());
    mMap.setOnInfoWindowClickListener(空);
    mMap.setOnMarkerClickListener(本);
    按钮哑=(按钮)infoWindow.findViewById(R.id.dummy);
    dummy.setVisibility(View.VISIBLE);
    dummy.setOnClickListener(新OnClickListener(){

        @覆盖
        公共无效的onClick(视图v){
            Toast.makeText(MarkerView.this,虚拟按钮,Toast.LENGTH_SHORT).show();

        }
    });
}


类CustomInfoAdapter实现InfoWindowAdapter {


    @覆盖
    公共查看getInfoContents(标记为arg0){
        displayView(为arg0);
        返回信息窗口;
    }

    @覆盖
    公共查看getInfoWindow(标记为arg0){

        返回null;
    }


}


公共无效displayView(标记为arg0){

    ((ImageView的)infoWindow.findViewById(R.id.badge))setImageResource(R.drawable.arrow)。
    ((ImageView的)infoWindow.findViewById(R.id.badge))。setOnClickListener(新OnClickListener(){

        @覆盖
        公共无效的onClick(视图v){
            Toast.makeText(MarkerView.this,箭图像,Toast.LENGTH_SHORT).show();

        }
    });
     ((TextView的)infoWindow.findViewById(R.id.title))的setText(arg0.getTitle());
     ((TextView的)infoWindow.findViewById(R.id.snippet))的setText(arg0.getTitle());

}


@覆盖
公共布尔onMarkerClick(标记为arg0){
    如果(arg0.equals(奈)){

        infoWindow.setClickable(假);

    }
    返回false;
}


@覆盖
公共无效onInfoWindowClick(标记为arg0){
    Toast.makeText(MarkerView.this,信息窗口,Toast.LENGTH_SHORT).show();
}
 

解决方案

请参阅信息窗口中点击事件在此的链接

信息窗口不是一个实时视图,而该视图呈现为一个图像到地图上。这样一来,您对视图设置的任何监听器被忽略,你不能在视图上的各个部分点击事件区分开来。建议您不要将交互式组件 - 如按钮,复选框或文本输入 - 。您的自定义信息窗口中的

I am using Google Map API V2 and i have created a custom InfoWindow for a Marker on map.In this InfoWindow i have a button.

My problem is unable to set Onclicklistener/functioning to that Button(Dummy).Any one give me some idea to solve this :

Here is code snippet:

public class MarkerView extends FragmentActivity implements OnMarkerClickListener,OnInfoWindowClickListener{

private GoogleMap mMap;
private Marker chennai;
private View infoWindow;
@Override
protected void onCreate(Bundle arg0) {
    super.onCreate(arg0);
    setContentView(R.layout.basic_demo);

    infoWindow=getLayoutInflater().inflate(R.layout.custom_info_contents, null);

    mMap=((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
    chennai=mMap.addMarker(new MarkerOptions().position(new LatLng(13.0810, 80.274)).anchor(2, 1).title("Android").snippet("Snippet").icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));
    mMap.setInfoWindowAdapter(new CustomInfoAdapter());
    mMap.setOnInfoWindowClickListener(null);
    mMap.setOnMarkerClickListener(this);
    Button dummy=(Button) infoWindow.findViewById(R.id.dummy);
    dummy.setVisibility(View.VISIBLE);
    dummy.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Toast.makeText(MarkerView.this, "Dummy Button", Toast.LENGTH_SHORT).show();

        }
    });
}


class CustomInfoAdapter implements InfoWindowAdapter{


    @Override
    public View getInfoContents(Marker arg0) {
        displayView(arg0);
        return infoWindow;
    }

    @Override
    public View getInfoWindow(Marker arg0) {

        return null;
    }


}


public void displayView(Marker arg0) {

    ((ImageView)infoWindow.findViewById(R.id.badge)).setImageResource(R.drawable.arrow);
    ((ImageView)infoWindow.findViewById(R.id.badge)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Toast.makeText(MarkerView.this, "Arrow Image", Toast.LENGTH_SHORT).show();

        }
    });
     ((TextView)infoWindow.findViewById(R.id.title)).setText(arg0.getTitle());
     ((TextView)infoWindow.findViewById(R.id.snippet)).setText(arg0.getTitle());

}


@Override
public boolean onMarkerClick(Marker arg0) {
    if(arg0.equals(chennai)){

        infoWindow.setClickable(false);

    }
    return false;
}


@Override
public void onInfoWindowClick(Marker arg0) {
    Toast.makeText(MarkerView.this, "Info window", Toast.LENGTH_SHORT).show();
}

解决方案

Please refer Info window click events in this link

Info window is not a live View, rather the view is rendered as an image onto the map. As a result, any listeners you set on the view are disregarded and you cannot distinguish between click events on various parts of the view. You are advised not to place interactive components — such as buttons, checkboxes, or text inputs — within your custom info window.

这篇关于在谷歌地图Android的V2自定义信息窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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