2015-05-09 151 views

回答

1

标题叫做InfoWindow。要实现您的自定义窗口,您需要:

1)创建实现GoogleMap.InfoWindowAdapter接口的类。像这样的东西(在这种情况下只是TextView):

@Override 
public void onMapReady(final GoogleMap map) { 
    ... 
    map.setInfoWindowAdapter(new MapItemAdapter(this)); 
    ... 
} 
+0

凡图像可设置为:

public class MapItemAdapter implements GoogleMap.InfoWindowAdapter { TextView tv; public MapItemAdapter(Context context) { tv = new TextView(context); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); tv.setLayoutParams(lp); tv.setGravity(Gravity.CENTER); } @Override public View getInfoWindow(Marker marker) { tv.setText(marker.getTitle()); return tv; } @Override public View getInfoContents(Marker marker) { return null; } } 

2)设置适配器GoogleMap您在onMapReady()回调接受? – Ken

+1

如果您只想要图像,请将'TextView'替换为'ImageView'。如果你想显示更复杂的窗口,创建自定义布局并将'ImageView'放置在里面。创建的视图只是在'getInfoWindow'方法中返回。 – skywall