百度地图4.0多个经纬度展示在地图上
2016-10-17 15:52
190 查看
public class YiYuanMapActivity extends BaseActivity{ private ArrayList<LatitudeModel> latitudeList; // 定位相关 LocationClient mLocClient; private MyLocationConfiguration.LocationMode mCurrentMode; public MyLocationListenner myListener = new MyLocationListenner(); boolean isFirstLoc = true; // 是否首次定位 /** * MapView 是地图主控件 */ private MapView mMapView; private BaiduMap mBaiduMap; // 初始化全局 bitmap 信息,不用时及时 recycle BitmapDescriptor bd = BitmapDescriptorFactory .fromResource(R.drawable.icon_gcoding); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); try { SDKInitializer.initialize(getApplicationContext()); } catch (Exception e) { // TODO: handle exception ToastUtils.shortToast(getApplicationContext(), "地图api初始化失败"); return; } setContentView(R.layout.activity_yi_yuan_map); mCurrentMode = MyLocationConfiguration.LocationMode.NORMAL; mMapView = (MapView) findViewById(R.id.bmapView); mBaiduMap = mMapView.getMap(); MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(14.0f); mBaiduMap.setMapStatus(msu); BitmapDescriptor centerBitmap = BitmapDescriptorFactory .fromResource(R.drawable.icon_geo); // 开启定位图层 mBaiduMap.setMyLocationEnabled(true); // 定位初始化 mLocClient = new LocationClient(getApplicationContext()); mLocClient.registerLocationListener(myListener); LocationClientOption option = new LocationClientOption(); option.setOpenGps(true); // 打开gps option.setCoorType("bd09ll"); // 设置坐标类型 option.setScanSpan(1000); option.setIsNeedAddress(true); mLocClient.setLocOption(option); mLocClient.start(); mBaiduMap .setMyLocationConfigeration(new MyLocationConfiguration( mCurrentMode, true, centerBitmap, 0, 0)); initOverlay(); } /** * 定位SDK监听函数 */ public class MyLocationListenner implements BDLocationListener { @Override public void onReceiveLocation(BDLocation location) { // map view 销毁后不在处理新接收的位置 if (location == null || mMapView == null) { return; } MyLocationData locData = new MyLocationData.Builder() .accuracy(location.getRadius()) // 此处设置开发者获取到的方向信息,顺时针0-360 .direction(0).latitude(location.getLatitude()) .longitude(location.getLongitude()).build(); mBaiduMap.setMyLocationData(locData); if (isFirstLoc) { isFirstLoc = false; LatLng ll = new LatLng(location.getLatitude(), location.getLongitude()); MapStatus.Builder builder = new MapStatus.Builder(); builder.target(ll).zoom(12); mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); } } public void onReceivePoi(BDLocation poiLocation) { } } private void initOverlay() { // add marker overlay for (int i = 0; i < latitudeList.size(); i++) { String ycode = latitudeList.get(i).ycode;//weidu String xcode = latitudeList.get(i).xcode; double lat = Double.parseDouble(ycode); double lng = Double.parseDouble(xcode); LatLng ll = new LatLng(lat, lng); MarkerOptions oo = new MarkerOptions().position(ll).icon(bd) .zIndex(9).draggable(true); // 掉下动画 oo.animateType(MarkerOptions.MarkerAnimateType.drop); Marker mMarkerA = (Marker) (mBaiduMap.addOverlay(oo)); mMarkerA = null; } mBaiduMap.setOnMarkerDragListener(new BaiduMap.OnMarkerDragListener() { public void onMarkerDrag(Marker marker) { } public void onMarkerDragEnd(Marker marker) { } public void onMarkerDragStart(Marker marker) { } }); } /** * 清除所有Overlay * * @param view */ public void clearOverlay(View view) { mBaiduMap.clear(); } /** * 重新添加Overlay * * @param view */ public void resetOverlay(View view) { clearOverlay(null); initOverlay(); } @Override protected void onDestroy() { // MapView的生命周期与Activity同步,当activity销毁时需调用MapView.destroy() mMapView.onDestroy(); super.onDestroy(); // 回收 bitmap 资源 bd.recycle(); } @Override protected void onResume() { super.onResume(); } @Override protected void onPause() { super.onPause(); } }
相关文章推荐
- Android 百度地图 SDK v3.3.0 (二)--- 地图定位和图层展示
- C#开发Android百度地图手机应用程序(多地图展示)
- 已知经纬度坐标,如何在地方坐标系下的地图上展示轨迹Arcgis for sl
- 高德地图获取经纬度、高德地图坐标转为百度地图坐标
- 百度地图,根据地图上任意一点的经纬度获取周边最近的POI位置信息
- 浅谈百度地图的简单开发之实现地图全景,内景展示功能(四)
- 百度地图最新版本sdk使用系列(八)-获取当前地图中心点的经纬度并计算与当前位置的距离
- 百度地图点击地图获取经纬度
- Android下百度地图开发(一):基础地图展示
- GPS经纬度及谷歌地图坐标转换为百度地图坐标,解决地图显示经纬度的偏移问题
- 百度地图android端URL.api直接展示地图处理
- 百度地图_根据地图上标记位置获取街道信息,以及经纬度信息
- GPS\谷歌\AMAP等地图经纬度转换为百度地图经纬度
- Android 开发之集成百度地图的定位与地图展示
- 百度地图,点击地图获取经纬度和地点
- 安卓开发——百度地图修改地图中心点为所需经纬度以及地图空白的问题
- 百度地图:用于打印的地图展示
- 使用echarts和百度地图经纬度绘制地图
- js 百度地图 获取地图经纬度范围
- 3.0+百度地图在地图初始化的时候就弹框展示一个信息框,而不是用户点击poi时才弹出