您的位置:首页 > 其它

百度地图(截图)

2015-12-16 14:17 246 查看
以下提供主要代码和思路:

1.根据传过来的经纬度,来标记:

LatLng latLng = new LatLng(Double.parseDouble("经度"),Double.parseDouble("维度"));
BitmapDescriptor bd = BitmapDescriptorFactory.fromResource(R.drawable.entertainment_logo);
OverlayOptions ooB = new MarkerOptions().position(latLng ).icon(bd);
mBaiduMap.addOverlay(ooB);
MapStatusUpdate mud=MapStatusUpdateFactory.newLatLng(friends_ll);
mBaiduMap.animateMapStatus(mud);


2.截图的时候,如果中间那个图标是自己xml放进去的话,那么截图没有那个图标,所以在截图之前,清空其他,添加个自己想要的标记:

BitmapDescriptor bd = BitmapDescriptorFactory.fromResource(R.drawable.entertainment_logo);
OverlayOptions ooB = new MarkerOptions().position("经纬度").icon(bd);
mBaiduMap.clear();
mBaiduMap.addOverlay(ooB);
MapStatusUpdate mud=MapStatusUpdateFactory.newLatLng(friends_ll);
mBaiduMap.animateMapStatus(mud);


3.截图(rect:设置要截取图片的宽高等设置,snapshotReadCallback这个接口会接收,截取好的图片,之后压缩到自己想要的大小的bitmap就ok.具体看百度地图API):

mBaiduMap.snapshotScope(rect, snapshotReadyCallback);
snapshotReadyCallback=new SnapshotReadyCallback(){
@Override
public void onSnapshotReady(Bitmap bitmap) {
       File file=new File(filename);    
       try {
           FileOutputStream fileOutputStream=new FileOutputStream(file);
           bitmap.compress(Bitmap.CompressFormat.PNG, 90, fileOutputStream);
           fileOutputStream.flush();
           fileOutputStream.close();
       } catch (FileNotFoundException e) {
           e.printStackTrace();
       } catch (IOException e) {
           e.printStackTrace();
       }
}
};


4.根据获取的地址,展示出:

Uri uri=Uri.fromFile(new File(filename));
Bitmap bitmap = decodeUriAsBitmap(uri);
xxx_map.setImageBitmap(bitmap);

5.百度地图接口网址:http://wiki.lbsyun.baidu.com/cms/androidsdk/doc/v3_6_1/

com.baidu.mapapi.map


接口 BaiduMap.SnapshotReadyCallback

封闭类:BaiduMap
public static interface BaiduMap.SnapshotReadyCallback

地图截屏回调接口

方法详细资料


onSnapshotReady

void onSnapshotReady(Bitmap snapshot)

地图截屏回调接口

参数:
snapshot
 - 截屏返回的 bitmap 数据
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: