2015-05-09 165 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