百度地图二(我的位置和覆盖物)


在上篇中的mainActitvity中加入

private boolean isFirstLocate = true;
//        地图显示位置
mMapView = (MapView) findViewById(R.id.map_view);
mBaiduMap = mMapView.getMap();
// 开启显示我的位置
mBaiduMap.setMyLocationEnabled(true);
    private void navigateTo(BDLocation location){

LatLng point = new LatLng(location.getLatitude()+0.12,location.getLongitude()+0.12);
// 显示所在位置
if (isFirstLocate){
LatLng ll = new LatLng(location.getLatitude(),location.getLongitude());
MapStatusUpdate update = MapStatusUpdateFactory.newLatLng(ll);
mBaiduMap.animateMapStatus(update);
update = MapStatusUpdateFactory.zoomTo(16f);
mBaiduMap.animateMapStatus(update);
isFirstLocate = false;
}
// 显示我的位置标识
MyLocationData.Builder locationBuilder = new MyLocationData.Builder();
locationBuilder.latitude(location.getLatitude());
locationBuilder.longitude(location.getLongitude());
MyLocationData locationData = locationBuilder.build();
mBaiduMap.setMyLocationData(locationData);

// 覆盖物的编写
// //构建Marker图标
// BitmapDescriptor bitmap = BitmapDescriptorFactory
// .fromResource(R.drawable.apple);
// OverlayOptions options = new MarkerOptions()
// .position(point)// 设置marker的位置
// .icon(bitmap)// 设置marker的图标
// .zIndex(9)// 設置marker的所在層級
// .draggable(true);// 设置手势拖拽
// // 在地图上添加marker,并显示
// mBaiduMap.addOverlay(options);
}
if (bdLocation.getLocType()==BDLocation.TypeGpsLocation){
currentPostion.append("GPS");
navigateTo(bdLocation);
}else if (bdLocation.getLocType()==BDLocation.TypeNetWorkLocation){
currentPostion.append("网络");
navigateTo(bdLocation);
}
原文地址:https://www.cnblogs.com/tflike/p/9453284.html