如何通过将 google 地图片段添加到标记来隐藏它们?
How do I hide google maps snippets by adding them to the marker?
我使用 google 地图并想添加片段,但我不想向我展示它们。我尝试了一切,但没有找到解决方案。也许有人知道如何隐藏用户代码段?
map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter(){
@Override
public View getInfoWindow(Marker marker) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
View v = getLayoutInflater().inflate(R.layout.custom_maps_window_info, null);
TextView title = (TextView) v.findViewById(R.id.custom_marker_title);
title.setText(marker.getTitle());
return v;
}
});
添加标记
map.addMarker(new MarkerOptions()
.title("TITLE NAME")
.icon(markerIcon)
.position(new LatLng(0, 0))
.snippet("TEST") /* <- hide */
);
只需要从地图信息中隐藏片段windows
谢谢! :)
尝试
if(marker.getSnippet().equals(true)) {
marker.setSnippet(null);
}
或
map.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
marker.hideInfoWindow();
}
});
创建自定义信息 window。
Class:
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.app.myrydeo.R;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.Marker;
public class CustomInfoWindow implements GoogleMap.InfoWindowAdapter {
View myView;
public CustomInfoWindow(Context context) {
myView = LayoutInflater.from(context).inflate(R.layout.info_window, null);
}
@Override
public View getInfoWindow(Marker marker) {
TextView txtPickupTitle = myView.findViewById(R.id.txtPickupInfo);
txtPickupTitle.setText(marker.getTitle());
return myView;
}
@Override
public View getInfoContents(Marker marker) {
return null;
}
}
布局:
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardElevation="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center"
android:background="#ffffff"
android:gravity="center"
android:weightSum="10"
android:padding="10dp">
<ImageView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:src="@drawable/home"/>
<LinearLayout
android:layout_marginLeft="10dp"
android:orientation="vertical"
android:layout_weight="9"
android:layout_width="0dp"
android:layout_height="wrap_content">
<TextView
android:id="@+id/txtPickupInfo"
android:text="Pickup Here"
android:textColor="#000000"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
在你的地图上activity:
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.getUiSettings().setZoomGesturesEnabled(true);
mMap.setInfoWindowAdapter(new CustomInfoWindow(this));
}
它的作用是替换默认信息 window 但不会删除调用的代码段。因此,在您调用标记的地方,调用该标记中的代码段,它仍将保留其值。
我使用 google 地图并想添加片段,但我不想向我展示它们。我尝试了一切,但没有找到解决方案。也许有人知道如何隐藏用户代码段?
map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter(){
@Override
public View getInfoWindow(Marker marker) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
View v = getLayoutInflater().inflate(R.layout.custom_maps_window_info, null);
TextView title = (TextView) v.findViewById(R.id.custom_marker_title);
title.setText(marker.getTitle());
return v;
}
});
添加标记
map.addMarker(new MarkerOptions()
.title("TITLE NAME")
.icon(markerIcon)
.position(new LatLng(0, 0))
.snippet("TEST") /* <- hide */
);
只需要从地图信息中隐藏片段windows
谢谢! :)
尝试
if(marker.getSnippet().equals(true)) {
marker.setSnippet(null);
}
或
map.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
marker.hideInfoWindow();
}
});
创建自定义信息 window。
Class:
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.app.myrydeo.R;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.Marker;
public class CustomInfoWindow implements GoogleMap.InfoWindowAdapter {
View myView;
public CustomInfoWindow(Context context) {
myView = LayoutInflater.from(context).inflate(R.layout.info_window, null);
}
@Override
public View getInfoWindow(Marker marker) {
TextView txtPickupTitle = myView.findViewById(R.id.txtPickupInfo);
txtPickupTitle.setText(marker.getTitle());
return myView;
}
@Override
public View getInfoContents(Marker marker) {
return null;
}
}
布局:
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardElevation="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center"
android:background="#ffffff"
android:gravity="center"
android:weightSum="10"
android:padding="10dp">
<ImageView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:src="@drawable/home"/>
<LinearLayout
android:layout_marginLeft="10dp"
android:orientation="vertical"
android:layout_weight="9"
android:layout_width="0dp"
android:layout_height="wrap_content">
<TextView
android:id="@+id/txtPickupInfo"
android:text="Pickup Here"
android:textColor="#000000"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
在你的地图上activity:
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.getUiSettings().setZoomGesturesEnabled(true);
mMap.setInfoWindowAdapter(new CustomInfoWindow(this));
}
它的作用是替换默认信息 window 但不会删除调用的代码段。因此,在您调用标记的地方,调用该标记中的代码段,它仍将保留其值。