您的位置:首页 > 移动开发 > Android开发

android百度地图自定义覆盖物

2015-06-03 12:23 330 查看

android百度地图自定义覆盖物

参考资料

BitmapDescriptorFactory.fromView(view) 报错

View, Bitmap, layout与系统底层调用的关系

百度地图中可以使用BitmapDescriptor将view转化为view类

View, Bitmap, layout属系统显示高层类,都需要转换为系统底层进行显示。这三者可以使用SDK中的方法进行互相转换,转换时需要注意系统资源占用问题。

注意的问题

使用LinearLayout进行转换,具体可能是百度SDK的bug

注意不要把经纬度传反了!!!!

代码

public void setOverlays(ArrayList<Place> places) {

int placeNumber = places.size();
for (int i = 0; i < placeNumber; i++) {
Place place = places.get(i);

LatLng llA = new LatLng(place.getLatitude(), place.getLongitude());

// 初始化覆盖物
View inflatedView = mInflater
.inflate(R.layout.map_item_place, null);
TextView tvPlaceName = (TextView) inflatedView
.findViewById(R.id.tv_place_name);
TextView tvMessagesNumber = (TextView) inflatedView
.findViewById(R.id.tv_message_number);
tvPlaceName.setText(place.getPlaceName());
tvMessagesNumber.setText(place.getCommentsNumber() + "条吐槽");
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory
.fromView(inflatedView);
OverlayOptions ooA = new MarkerOptions().position(llA)
.icon(bitmapDescriptor).zIndex(9).draggable(true);

Marker marker = (Marker) (mBaiduMap.addOverlay(ooA));

Bundle bundle = new Bundle();
bundle.putInt(Constant.PLACE_ITEM_INT, i);
marker.setExtraInfo(bundle);
mMarkers.add(marker);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: