简体   繁体   English

谷歌 map 标记 showinfowWindow 自定义 Android

[英]Google map marker showinfowWindow customize Android

In my app, I have to show the information about the marker at position.在我的应用程序中,我必须在 position 处显示有关标记的信息。 This is my work code.这是我的工作代码。

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

This looks like this image:这看起来像这样的图像: 在此处输入图像描述

I want looks like this iamge:我想要看起来像这样的iamge: 在此处输入图像描述 If you have any method, please vote me.如果你有任何方法,请投票给我。

Try this.尝试这个。

marker.setInfoWindowAnchor(1f,1f)

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

Edit:编辑:

For a custom infoWindow you have to make a concrete implementation of GoogleMap.InfoWindowAdapter and inflate your custom_info_window_layout.xml file in the getInfoWindow(Marker marker) method.对于自定义 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;
}

} }

And finally set this CustomInfoWindowAdapter on the map.最后在 map 上设置这个CustomInfoWindowAdapter

map.setInfoWindowAdapter(new CustomInfoWindowAdapter(MainActivity.this))
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

在此处输入图像描述

Specifies the point in the marker image at which to anchor the info window when it is displayed.指定标记图像中显示信息时锚定信息 window 的点。 The default is the top middle of the image.默认是图像的顶部中间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM