我想自己设计一个不同的信息窗口,但找不到合适的方法。
如图所示:
当我点击标记时,我想在底部显示一个栏。我将在那里提供有关标记的详细信息。 (它将包括名称、地址、图标)并且这些名称、地址必须是可点击的。
有哪些可能的方法(ways)来做?
最佳答案
GoogleMap.InfoWindowAdapter
如果您想在屏幕底部显示标记详细信息,将显示带有标记的自定义窗口隐藏自定义窗口并在 MapView 上显示自定义 View
主.xml
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.iphonealsham.speedli.activitys.MapsActivity" />
<LinearLayout
android:id="@+id/linearLayoutCustomView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/textViewTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textViewOtherDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>
在onMarkerClick
中通过return true
隐藏InfoWidow并显示customView
@Override
public void onMapReady(GoogleMap googleMap) {
mGoogleMap = googleMap;
mGoogleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
Log.d("GoogleMap", " click");
//focus the market
mGoogleMap.animateCamera(CameraUpdateFactory.newLatLng(marker.getPosition()));
if (linearLayoutCustomView.getVisibility() == View.VISIBLE)
linearLayoutCustomView.setVisibility(View.GONE);
else
displayCustomeInfoWindow(marker);
return true;
}
});
}
在 View 中设置详细信息
private void displayCustomeInfoWindow(Marker marker) {
linearLayoutCustomView.setVisibility(View.VISIBLE);
TextView textViewTitle = linearLayoutCustomView.findViewById(R.id.textViewTitle);
TextView textViewOtherDetails = linearLayoutCustomView.findViewById(R.id.textViewOtherDetails);
textViewTitle.setText(marker.getTitle());
textViewOtherDetails.setText("LatLong :: " + marker.getPosition().latitude + "," + marker.getPosition().longitude);
}
关于Android 谷歌地图自定义信息窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48124134/