适用于 对InfoWindow最终相对位置需要看上去有自定义偏移的需求场景,通过设置百度地图中心的方式,适当的偏移计算,可以让InfoWindow看起来更友好
/**
* 设置百度地图中心
*/
private void setMapCenter(LatLng latLng) {
MapStatus.Builder builder = new MapStatus.Builder();
builder.target(latLng);
builder.zoom(zoomLevel);
baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
}
/**
* 显示InfoWindow
*/
private void showInfoWindow(final Marker marker) {
infoWindowDetails = new InfoWindow(cdv, marker.getPosition(), -marker.getIcon().getBitmap().getHeight());
baiduMap.showInfoWindow(infoWindowDetails);
Point point = baiduMap.getProjection().toScreenLocation(marker.getPosition());//经纬坐标转屏幕坐标
point.y -= marker.getIcon().getBitmap().getHeight() * 2;//自定义设置地图中心的偏移量
latLngCenter = baiduMap.getProjection().fromScreenLocation(point);//屏幕坐标转经纬坐标
setMapCenter(latLngCenter);
}