在我的应用程序中,我必须在位置上显示标记的信息,这是我的工作代码。
mPerth = mMap.addMarker(new MarkerOptions()
.position(PERTH)
.title("Perth")
.snippet("Population: Perth")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE)));
mPerth.showInfoWindow();
试试这个。
marker.setInfoWindowAnchor(1f,1f)
编辑。
对于一个自定义的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))