在InfoWindow Google Map上添加路由按钮

时间:2017-01-11 19:05:48

标签: android google-maps infowindow

我为Google地图创建了一个自定义的infoWindow。

这是布局xml文件

 <?xml version="1.0" encoding="utf-8"?>
 <GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:columnCount="2"
  android:rowCount="2"
  android:orientation="vertical">

    <TextView
        android:id="@+id/title"
        android:layout_height="wrap_content"
        android:textSize="18sp"
        android:textStyle="bold"
        android:layout_row="0"
        android:layout_column="1"
        android:textColor="@color/DarkerGreen"
        android:textAlignment="center"
        android:layout_width="250dp" />

    <TextView
        android:id="@+id/snippet"
        android:layout_height="wrap_content"
        android:textSize="12sp"
        android:layout_row="1"
        android:layout_column="1"
        android:textColor="@color/DarkerGreen"
        android:textAlignment="center"
        android:layout_width="250dp" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="5dp"
        android:adjustViewBounds="true"
        android:src="@drawable/info_logo"
        android:layout_rowSpan="2"
        android:layout_row="0"
        android:layout_column="0"
        android:layout_marginEnd="5dp"
        android:contentDescription="@string/marker_icon_desc" />
 </GridLayout>

这是我的infowindow Class

class MyInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {

    private final View myContentsView;

    MyInfoWindowAdapter() {
        myContentsView = getLayoutInflater().inflate(R.layout.map_info_content, null);
    }

    @Override
    public View getInfoWindow(Marker marker) {
        return null;
    }

    @Override
    public View getInfoContents(Marker marker) {

        TextView tvTitle = ((TextView) myContentsView.findViewById(R.id.title));
        tvTitle.setText(marker.getTitle());
        TextView tvSnippet = ((TextView) myContentsView.findViewById(R.id.snippet));
        tvSnippet.setText(marker.getSnippet());

        return myContentsView;
    }
}

我想在标记infoWindow本身添加路线按钮和谷歌地图按钮。默认情况下,它显示在屏幕的右下角。但我也想让它出现在infowindow里面。我是Android开发的新手,这是我的第一个应用程序,我尝试了很多,但无法成功。在此先感谢您的帮助和时间。如果我错过了任何信息,请告诉我。

编辑: 我的意思是没有良好的英语。我实际上想要实现与单击路由按钮相同的行为,问题是如何以及在按钮单击事件上传递什么参数,以使其行为与单击默认路由按钮的行为相同。即它进入谷歌地图网站,并应该在标记位置和我当前位置之间的路线。

0 个答案:

没有答案