【问题标题】:How do I hide google maps snippets by adding them to the marker?如何通过将谷歌地图片段添加到标记来隐藏它们?
【发布时间】:2017-08-12 11:56:25
【问题描述】:

我使用谷歌地图并想添加 sn-ps,但我不想向我展示它们。我尝试了一切,但我没有找到解决方案。也许有人知道如何隐藏用户 sn-ps?

        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 */
                    );

只需要在地图信息窗口中隐藏 sn-ps

谢谢! :)

【问题讨论】:

  • 我想传递这个文本并通过 sn-ps 将它转移到另一个活动,但我无法在用户上成功。

标签: android google-maps google-maps-markers


【解决方案1】:

试试

if(marker.getSnippet().equals(true)) {
                        marker.setSnippet(null);
                    }

map.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
            @Override
            public void onInfoWindowClick(Marker marker) {
                marker.hideInfoWindow();
            }
        });

【讨论】:

  • map.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() { @Override public void onInfoWindowClick(Marker marker) { marker.hideInfoWindow(); } });
  • Joyson,是的,我之前尝试过,但没有帮助。但它不起作用。
  • 试试@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()); marker.setSnippet(""); return v; }
  • 我想通过 sn-ps 传递这个文本并把它转移到另一个活动,但我无法在用户上成功。
  • 创建一个全局变量,然后放入 infoContents var = marker.getsn-p();最后,访问全局变量
【解决方案2】:

创建自定义信息窗口。

类:

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>

关于您的地图活动:

public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
        mMap.getUiSettings().setZoomControlsEnabled(true);
        mMap.getUiSettings().setZoomGesturesEnabled(true);
        mMap.setInfoWindowAdapter(new CustomInfoWindow(this));
}

它的作用是替换默认的信息窗口,但不会删除调用的 sn-p。因此,在您调用标记的地方,调用该标记中的 sn-p,它仍将保留其值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多