【问题标题】:GWT: Adding click handler to an infoWindow - using Google Maps V1GWT:将点击处理程序添加到 infoWindow - 使用 Google Maps V1
【发布时间】:2015-05-20 06:29:51
【问题描述】:

在我的 GWT 项目中,我有一个地图,当用户单击我在地图上绘制的各种标记之一时,它会显示一个信息窗口。一旦我有了坐标,mark_coords,这就是我添加 infoWindow 的方式:

                        map.getInfoWindow().open(mark_coords,
                                new InfoWindowContent(name +  "<br />" + description));

我想在 infoWindow 中添加一个可点击的图标。但是,我似乎找不到任何文档来说明如何在没有各种库的情况下使用 Google Maps V1 做到这一点。

如果有人有任何建议,将不胜感激!

【问题讨论】:

    标签: java google-maps gwt infowindow


    【解决方案1】:

    您可以添加带有 ImageView 的 XML 文件,并为 ImageView 添加setOnClickListener

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <ImageView
            android:id="+@id/imageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dp"
            android:adjustViewBounds="true"
            android:src="@drawable/ic_launcher"/>
    </LinearLayout>
    

    然后您可以创建一个 InfoWindowAdapter,并覆盖 getInfoContents 方法。

      class MyInfoWindowAdapter implements InfoWindowAdapter {
    
          private final View myContentsView;
    
          MyInfoWindowAdapter() {
              myContentsView = getLayoutInflater().inflate(R.layout.custom_info_contents, null);
          }
    
          @Override
          public View getInfoContents(Marker marker) {
             ImageView imageView = ((ImageView)myContentsView.findViewById(R.id.imageView))
             imageView.setOnClickListener(new OnClickListener() {
                 @Override
                 public void onClick(View arg0) {
    
                 }
              });
    
             return myContentsView;
          }
    
          @Override
          public View getInfoWindow(Marker marker) {
           // TODO Auto-generated method stub
           return null;
          }
    
     }
    

    最后您可以通过map.setInfoWindowAdapter(new MyInfoWindowAdapter()); 调用您的自定义信息窗口。

    您可以访问this short tutorial了解更多详情。

    【讨论】:

    • 好的,感谢您的帮助..但这是一个 GWT 项目,不幸的是不是 android..
    • 您可能想为 GWT 结帐 this sample demo
    猜你喜欢
    • 2013-01-18
    • 2013-03-14
    • 2012-03-23
    • 1970-01-01
    • 2012-03-14
    • 2021-03-19
    • 2012-03-29
    • 2021-10-20
    • 1970-01-01
    相关资源
    最近更新 更多