java - 谷歌地图标记showinfowindow自定义Android

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

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

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

这看起来像这样的图片: enter image description here

我想要看起来像这样的图片: enter image description here 如果你有什么方法,请投票给我。

最佳答案

试试这个。

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 文件。

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;
}

}

最后在 map 上设置这个CustomInfoWindowAdapter

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

关于java - 谷歌地图标记showinfowindow自定义Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62350019/

相关文章:

java - JDBC DatabaseMetaData 说我的 mysql 服务器不支持 namedParameters 并因此抛出空指针异常

android - 在 Actionbar 中隐藏 SubMenu 和 SearchView

javascript - 将 HTML 数据属性中的数组转换为 Javascript 数组

java - Android应用静态分析

java - Spring:如何用常量值替换构造函数参数?

java - Jackson 循环依赖只是通过深度而不是同时通过深度和广度

javascript - Sencha Touch - Map.Geo = null

android - 使用 Matrix 的 rotateM() 从 SurfaceTexture 旋转矩阵但损坏视频输出

android - GridLayoutManager setSpanSizeLookup 不工作

javascript - 使用输入类型 ="range"更改 Circle google map 的半径