我已将自定义 InfoWindow 添加到我的 GoogleMap 对象中,如下所示
mMap.setInfoWindowAdapter(new InfoWindowAdapter()
{
@Override
public View getInfoContents(Marker marker)
{
return null;
}
@Override
public View getInfoWindow(Marker marker)
{
View v = getLayoutInflater().inflate(R.layout.marker_info_window_layout,null,false);
TextView title = (TextView) v.findViewById(R.id.title);
TextView desc = (TextView) v.findViewById(R.id.desc);
TextView level = (TextView) v.findViewById(R.id.level);
final int position = Integer.valueOf(marker.getSnippet());
Players player = playersArray.get(position);
title.setText(player.name);
level.setText("Level " + String.valueOf(player.level));
return v;
}
效果很好。但是,我的布局的箭头尖端离标记很远。所以我想添加一个偏移量,让我们至少说 50px。
根据此处给出的文档
https://developers.google.com/maps/documentation/javascript/reference#MarkerOptions
anchorPoint : The offset from the marker's position to the tip of an InfoWindow that has been opened with the marker as anchor.
但是当我这样做时
mMap.addMarker(new MarkerOptions()
.position(p)
.anchor(0,50)
.snippet(String.valueOf(position))
.draggable(false)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
标记只是消失了,甚至不显示..有什么问题?如果没有锚选项,它们可以正常工作。