谷歌地图标记显示infowWindow自定义Android

问题描述 投票:0回答:1

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

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如果你有什么方法,请投给我。

java android google-maps google-maps-markers google-maps-android-api-2
1个回答
0
投票

试试这个。

marker.setInfoWindowAnchor(1f,1f)

https:/developers.google.comandroidreferencecomgoogleandroidgmsmapsmodelMarker#public-void-setinfowindowanchor-float-anchoru,-float-anchorv。

编辑。

对于一个自定义的infoWindow,你必须做一个具体的实现。GoogleMap.InfoWindowAdapter 并给你充气 自定义_信息_窗口_布局.xml。 方法中的 getInfoWindow(Marker marker) 文件。

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))

0
投票
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

enter image description here

指定标记图像中显示信息窗口时的固定点。默认值是图像的中上部。

© www.soinside.com 2019 - 2024. All rights reserved.