【问题标题】:Google map marker showinfowWindow customize Android谷歌地图标记 showinfowWindow 自定义 Android
【发布时间】:2020-10-02 14:38:25
【问题描述】:

在我的应用程序中,我必须在位置显示有关标记的信息。 这是我的工作代码。

mPerth = mMap.addMarker(new MarkerOptions()
        .position(PERTH)
        .title("Perth")
        .snippet("Population: Perth")
        .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE)));
mPerth.showInfoWindow();

这看起来像这样的图像:

我想要看起来像这样的 iamge: 如果你有什么方法,请给我投票。

【问题讨论】:

  • 我想将 infoWindow 移动到标记的右侧。我还没有找到那个解决方案。

标签: java android google-maps google-maps-markers google-maps-android-api-2


【解决方案1】:

试试这个。

marker.setInfoWindowAnchor(1f,1f)

https://developers.google.com/android/reference/com/google/android/gms/maps/model/Marker#public-void-setinfowindowanchor-float-anchoru,-float-anchorv

编辑:

对于自定义 infoWindow,您必须具体实现 GoogleMap.InfoWindowAdapter 并在 getInfoWindow(Marker marker) 方法中扩充您的 custom_info_window_layout.xml 文件。 p>

public class CustomInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {

Activity context;
CustomInfoWindow(Activity  context){
    this.context =context;
}

@Override
public View getInfoWindow(Marker marker) {
    View view = context.getLayoutInflater().inflate(R.layout.custom_info_window_layout, null);

    TextView title =(TextView) view.findViewById(R.id.tv_title);
    TextView snippet =(TextView) view.findViewById(R.id.tv_snippet);

    title.setText(marker.getTitle());
    snippet.setText(marker.getSnippet());

    return view;
}

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

}

最后在地图上设置这个 CustomInfoWindowAdapter

map.setInfoWindowAdapter(new CustomInfoWindowAdapter(MainActivity.this))

【讨论】:

  • 谢谢,它对我有用。我需要自定义信息窗口。如果您知道这一点,请添加评论。
【解决方案2】:
static final LatLng PERTH = new LatLng(-31.90, 115.86);
Marker marker = mMap.addMarker(new MarkerOptions()
                    .position(PERTH)
                    .anchor(0.5,0.5)
                    .rotation(90.0)
                    .infoWindowAnchor(0.5,0)); // add this line

指定标记图像中显示信息窗口时锚定信息窗口的点。默认是图像的顶部中间。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-13
    • 2016-01-16
    • 2013-08-21
    • 1970-01-01
    • 2015-10-19
    相关资源
    最近更新 更多