Saj*_*ara 5 customization android google-maps onclick infowindow
嗨我想在android应用程序中添加标记信息窗口到我的谷歌地图.到目前为止,我已添加自定义信息窗口,它有图像和按钮.点击标记然后显示信息窗口,然后用户点击后,我的目标单击按钮后,窗口中的按钮关闭信息窗口并执行一些活动.但我无法识别用户在标记信息窗口中单击按钮的时间.这是我的代码.Plz告诉我我的代码中哪里出错了.
googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {
// Use default InfoWindow frame
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
// Defines the contents of the InfoWindow
@Override
public View getInfoContents(Marker arg0) {
final View infoview = getLayoutInflater().inflate(R.layout.info_window,
null);
LatLng latLng = arg0.getPosition();
//tvLat.setText("Latitude:" + latLng.latitude);
//tvLng.setText("Longitude:" + latLng.longitude);
Button pickMe = (Button)infoview.findViewById(R.id.pickme);
pickMe.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Requested Send", Toast.LENGTH_SHORT).show();
}});
//String reverceGeoCode=new GetLocationAddress().getAddress(String.valueOf(latLng.latitude), String.valueOf(latLng.longitude));
//Toast.makeText(getApplicationContext(), "Rev :"+reverceGeoCode, Toast.LENGTH_LONG).show();
return infoview;
}
});
Run Code Online (Sandbox Code Playgroud)
这是我的customInfo-window xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Sajith Vijesekara"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp">
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:src="@drawable/driver" />
<Button
android:id="@+id/pickme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:text="Pick Me" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
谢谢Sajith
Com*_*are 11
引用文档:
注意:绘制的信息窗口不是实时视图.视图在返回时呈现为图像(使用View.draw(Canvas)).这意味着对视图的任何后续更改都不会被地图上的信息窗口反映出来.要稍后更新信息窗口(例如,在加载图像后),请调用showInfoWindow().此外,信息窗口将不会考虑正常视图(例如触摸或手势事件)的任何典型交互.但是,您可以在整个信息窗口中收听通用点击事件,如下节所述.
因此,您无法找到有人Button
在您的信息窗口中点击a .不过,欢迎您回复信息窗口上的任何位置的点击.
有人写了一个库来解决这个问题
https://github.com/Appolica/InteractiveInfoWindowAndroid
InteractiveInfoWindowAndroid是一个Android库,让您有机会在谷歌地图上显示交互式信息窗口.窗口的UI封装在您自己的片段中,并具有自己的生命周期.您只需将其传递给InfoWindowManager并将其显示在您想要的任何标记上方.
归档时间: |
|
查看次数: |
13885 次 |
最近记录: |