/** * 定位接收到的地址 **/ private void locationReceiveAddress() { if (receiveAddress == null) { return; } LatLng p = new LatLng(receiveAddress.getLatitude(), receiveAddress.getLongitude()); MarkerOptions markerOptions = new MarkerOptions(); /* 设置覆盖物图标 */ markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_openmap_focuse_mark)) .position(p) .visible(true); baiduMap.setOnMarkerClickListener(new BaiduMap.OnMarkerClickListener() { @Override public boolean onMarkerClick(Marker marker) { setSinglePoiDetail(); return true; } }); if (NetUtil.getInstance(SetFavoriteMapActivity.this).getCurrentNetType().equals(NetUtil.NetType.NETWORK_TYPE_NONE)) { // Snackbar.make(mAmosfPoiList,mAppConfig.getResources().getString(R.string.no_network), Snackbar.LENGTH_SHORT).show(); return; } /* 添加覆盖图层 */ baiduMap.addOverlay(markerOptions); baiduMap.setMapStatus(MapStatusUpdateFactory.newLatLngZoom(p, 17F)); }
private void initMapSetting() { mMapView.showZoomControls(false); mBaiduMap = mMapView.getMap(); // 开启定位图层 mBaiduMap.setMyLocationEnabled(true); //设置指南针 // UiSettings uiSettings = mBaiduMap.getUiSettings(); // uiSettings.setCompassEnabled(true); mBaiduMap.setCompassPosition(new Point(660,60)); //设置普通地图 mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL); //设置定位图层配置信息,只有先允许定位图层后设置定位图层配置信息才会生效 mBaiduMap.setMyLocationConfiguration(new MyLocationConfiguration( MyLocationConfiguration.LocationMode.NORMAL, false, null)); mBaiduMap.setBuildingsEnabled(false); //设置缩放级别 MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(16.0f); mBaiduMap.setMapStatus(msu); }
@Override public void onMapStatusChange(MapStatus mapStatus) { int currentClusterSize = mMarkerManager.getCollectionSize(); // Log.d("----", "onMapStatusChange: 地图状态正在改变:"+currentClusterSize); //地图的状态不停的改变,当聚合物集合的大小发生改变的时候,需要将recyclerView的显示给去掉 if(currentClusterSize != mLastClusterSize){ //取消recyclerView的显示,需要数据源和adapter的对象 mBaiduMap.hideInfoWindow(); } if (mRenderer instanceof BaiduMap.OnMapStatusChangeListener) { ((BaiduMap.OnMapStatusChangeListener) mRenderer).onMapStatusChange(mapStatus); } // Don't re-compute clusters if the map has just been panned/tilted/rotated. MapStatus position = mMap.getMapStatus(); if (mPreviousCameraPosition != null && mPreviousCameraPosition.zoom == position.zoom) { return; } mPreviousCameraPosition = mMap.getMapStatus(); cluster(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //在使用SDK各组件之前初始化context信息,传入ApplicationContext //注意该方法要再setContentView方法之前实现 SDKInitializer.initialize(getApplicationContext()); setContentView(R.layout.activity_location_baidu_map); //获取地图控件引用 mMapView = (MapView) findViewById(R.id.bmapView); mBaiduMap = mMapView.getMap(); //普通地图 // mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL); //卫星地图 mBaiduMap.setMapType(BaiduMap.MAP_TYPE_SATELLITE); //空白地图, 基础地图瓦片将不会被渲染。在地图类型中设置为NONE,将不会使用流量下载基础地图瓦片图层。使用场景:与瓦片图层一起使用,节省流量,提升自定义瓦片图下载速度。 // mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NONE); }
public int getMapType(Context context) { final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); String mapType = sharedPref.getString(PREF_MAP_TYPE, DEFAULT_MAP_TYPE); if (mapType.equalsIgnoreCase(MAP_TYPE_SATELLITE)) { return BaiduMap.MAP_TYPE_SATELLITE; } else if (mapType.equalsIgnoreCase(MAP_TYPE_NORMAL)) { return BaiduMap.MAP_TYPE_NORMAL; } else if (mapType.equalsIgnoreCase(MAP_TYPE_NONE)) { return BaiduMap.MAP_TYPE_NONE; } else { return BaiduMap.MAP_TYPE_SATELLITE; } }
private void updateBDMapStatus(BDLocation location) { final BaiduMap map = getBaiduMap(); final BaiduMapPrefFragment provider = (BaiduMapPrefFragment)(getProvider().getMapProviderPreferences()); final Context context = getActivity().getApplicationContext(); int mapType = provider.getMapType(context); map.setMapType(mapType); MyLocationData locData = new MyLocationData.Builder() .accuracy(location.getRadius()) .latitude(location.getLatitude()) .longitude(location.getLongitude()).build(); map.setMyLocationData(locData); LatLng ll = new LatLng(location.getLatitude(), location.getLongitude()); MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll); map.animateMapStatus(u); }
@Override public void updatePolygonsPaths(List<List<LatLong>> paths) { final BaiduMap map = getBaiduMap(); if (map == null) return; for (Polygon poly : mPolygonsPaths) { poly.remove(); } for (List<LatLong> contour : paths) { PolygonOptions pathOptions = new PolygonOptions(); pathOptions.fillColor(POLYGONS_PATH_DEFAULT_COLOR); final List<LatLng> pathPoints = new ArrayList<LatLng>(contour.size()); for (LatLong coord : contour) { pathPoints.add(MapUtils.coordToBaiduLatLng(coord)); } pathOptions.points(pathPoints); mPolygonsPaths.add((Polygon)map.addOverlay(pathOptions)); } }
@Override public void addCameraFootprint(FootPrint footprintToBeDraw) { final BaiduMap map = getBaiduMap(); if (map == null) return; PolygonOptions pathOptions = new PolygonOptions(); pathOptions.stroke(mFootprintStroke); pathOptions.fillColor(FOOTPRINT_FILL_COLOR); final List<LatLng> pathPoints = new ArrayList<LatLng>(footprintToBeDraw.getVertexInGlobalFrame().size()); for (LatLong coord : footprintToBeDraw.getVertexInGlobalFrame()) { pathPoints.add(MapUtils.coordToBaiduLatLng(coord)); } pathOptions.points(pathPoints); map.addOverlay(pathOptions); }
@Override public void loadCameraPosition() { final BaiduMap map = getBaiduMap(); if (map == null) return; final SharedPreferences settings = mAppPrefs.prefs; final MapStatus.Builder camera = new MapStatus.Builder(); camera.rotate(settings.getFloat(PREF_BEA, DEFAULT_BEARING)); camera.overlook(settings.getFloat(PREF_TILT, DEFAULT_TILT)); camera.zoom(settings.getFloat(PREF_ZOOM, DEFAULT_ZOOM_LEVEL)); camera.target(new LatLng(settings.getFloat(PREF_LAT, DEFAULT_LATITUDE), settings.getFloat(PREF_LNG, DEFAULT_LONGITUDE))); map.setMapStatus(MapStatusUpdateFactory.newMapStatus(camera.build())); }
/** * 设置底图显示模式 * * @param view */ public void setMapMode(View view) { boolean checked = ((RadioButton) view).isChecked(); switch (view.getId()) { case R.id.normal: if (checked) { mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL); } break; case R.id.statellite: if (checked) { mBaiduMap.setMapType(BaiduMap.MAP_TYPE_SATELLITE); } break; default: break; } }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.btn1: mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL);//普通地图 break; case R.id.btn2: mBaiduMap.setMapType(BaiduMap.MAP_TYPE_SATELLITE);//卫星地图 break; case R.id.btn3: mBaiduMap.setTrafficEnabled(true);//交通 break; case R.id.btn4: mBaiduMap.setBaiduHeatMapEnabled(true);//热力 break; } }
private void initView() { mMapView = (MapView) findViewById(R.id.id_bmapView); mBaiduMap = mMapView.getMap(); MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(17.0f);//缩放等级17=100m mBaiduMap.setMapStatus(msu); mLocationMode = MyLocationConfiguration.LocationMode.NORMAL; //隐藏缩放控件和百度logo int childCount = mMapView.getChildCount(); for (int i = 0; i < childCount; i++) { View child = mMapView.getChildAt(i); if (child instanceof ZoomControls || child instanceof ImageView) { child.setVisibility(View.GONE); } } //改变比例尺的位置 final int screenheight = this.getWindowManager().getDefaultDisplay().getHeight(); mBaiduMap.setOnMapLoadedCallback(new BaiduMap.OnMapLoadedCallback() { @Override public void onMapLoaded() { mMapView.setScaleControlPosition(new Point(200, screenheight - 307)); } }); }
@Override protected void initViews() { SDKInitializer.initialize(getApplicationContext()); setContentView(R.layout.activity_hospital_periphery_navigation); setTitleBack("周边商户"); rbDrug = (RadioButton) findViewById(R.id.rb_drug); rbHotel = (RadioButton) findViewById(R.id.rb_hotel); rbBank = (RadioButton) findViewById(R.id.rb_bank); rbIce = (RadioButton) findViewById(R.id.rb_ice); mMapView = (MapView) findViewById(R.id.mv); mBaiduMap = mMapView.getMap(); //普通地图 mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL); //设定中心点坐标 LatLng centerPoint = new LatLng(31.3023280000, 120.5906890000); //定义地图状态 MapStatus mMapStatus = new MapStatus.Builder() .target(centerPoint) .zoom(18) .build(); //定义MapStatusUpdate对象,以便描述地图状态将要发生的变化 MapStatusUpdate mMapStatusUpdate = MapStatusUpdateFactory.newMapStatus(mMapStatus); //改变地图状态 mBaiduMap.setMapStatus(mMapStatusUpdate); }
public static MBound getExtendedBounds(BaiduMap map, MBound bound, Integer gridSize) { // Log.d("getExtendBounds", "size:"+gridSize); MBound tbounds = cutBoundsInRange(bound); System.out.println("getExtendedBounds---" + tbounds.getRightTop() + tbounds.getLeftBottom()); Projection projection = map.getProjection(); Point pixelNE = new Point(); Point pixelSW = new Point(); pixelNE = projection.toScreenLocation(tbounds.getRightTop()); pixelSW = projection.toScreenLocation(tbounds.getLeftBottom()); System.out.println("前pixelNE:" + pixelNE + "pixelSW:" + pixelSW); pixelNE.x += gridSize; pixelNE.y += gridSize; pixelSW.x -= gridSize; pixelSW.y -= gridSize; System.out.println("后pixelNE:" + pixelNE + "pixelSW:" + pixelSW); LatLng rightTop = projection.fromScreenLocation(pixelNE); LatLng leftBottom = projection.fromScreenLocation(pixelSW); System.out.println("getExtendedBounds---" + "rightTop:" + rightTop + "leftBottom:" + leftBottom); return new MBound(rightTop, leftBottom); }
/** * 通过一个BaiduMap 对象构造 * * @param baiduMap */ public OverlayManager(BaiduMap baiduMap) { mBaiduMap = baiduMap; // mBaiduMap.setOnMarkerClickListener(this); if (mOverlayOptionList == null) { mOverlayOptionList = new ArrayList<OverlayOptions>(); } if (mOverlayList == null) { mOverlayList = new ArrayList<Overlay>(); } }
private void initMarkerClickEvent() { // 对Marker的点击 mBaiduMap.setOnMarkerClickListener(new BaiduMap.OnMarkerClickListener() { @Override public boolean onMarkerClick(final Marker marker) { // 获得marker中的数据 if (marker != null && marker.getExtraInfo() != null) { BikeInfo bikeInfo = (BikeInfo) marker.getExtraInfo().get("info"); if (bikeInfo != null) updateBikeInfo(bikeInfo); } return true; } }); }
/** * 切换地图类型:这里做卫星地图和2D平面地图的切换 */ private void changeMapType() { if (mBaiduMap.getMapType() == BaiduMap.MAP_TYPE_NORMAL) { // 卫星地图 mBaiduMap.setMapType(BaiduMap.MAP_TYPE_SATELLITE); } else { // 普通地图 (默认) mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL); } }
/** * 构造函数设置默认的聚合物图形、文本颜色等 * @param context * @param map * @param clusterManager */ public DefaultClusterRenderer(Context context, BaiduMap map, ClusterManager<T> clusterManager) { mMap = map; mDensity = context.getResources().getDisplayMetrics().density; mIconGenerator = new IconGenerator(context); mIconGenerator.setContentView(makeSquareTextView(context)); //聚合之后,覆盖物集合的个数的数字颜色 // mIconGenerator.setTextAppearance(R.style.ClusterIcon_TextAppearance); mIconGenerator.setBackground(makeClusterBackground()); this.mImgView = mIconGenerator.getClusterImg(); mClusterManager = clusterManager; }
public ClusterManager(Context context, BaiduMap map, MarkerManager markerManager) { mMap = map; mMarkerManager = markerManager; mClusterMarkers = markerManager.newCollection(); mMarkers = markerManager.newCollection(); mRenderer = new DefaultClusterRenderer<T>(context, map, this); mImageView = mRenderer.getClusterImg(); mAlgorithm = new PreCachingAlgorithmDecorator<T>(new NonHierarchicalDistanceBasedAlgorithm<T>()); mClusterTask = new ClusterTask(); mRenderer.onAdd(); }
private void initMarkerClickEvent() { // 对Marker的点击 baiduMap.setOnMarkerClickListener(new BaiduMap.OnMarkerClickListener() { @Override public boolean onMarkerClick(final Marker marker) { // 获得marker中的数据 if (marker != null && marker.getExtraInfo() != null) { BikeInfo bikeInfo = (BikeInfo) marker.getExtraInfo().get("info"); if (bikeInfo != null) updateBikeInfo(bikeInfo); } return true; } }); }
@Override public void onClick(View view) { switch (view.getId()) { case R.id.exchange_map_fab: if (mBaiduMap.getMapType() == BaiduMap.MAP_TYPE_NORMAL) { mBaiduMap.setMapType(BaiduMap.MAP_TYPE_SATELLITE); } else { mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL); } break; } }
/** * ͨ��һ��BaiduMap ������ * * @param baiduMap */ public OverlayManager(BaiduMap baiduMap) { mBaiduMap = baiduMap; // mBaiduMap.setOnMarkerClickListener(this); if (mOverlayOptionList == null) { mOverlayOptionList = new ArrayList<OverlayOptions>(); } if (mOverlayList == null) { mOverlayList = new ArrayList<Overlay>(); } }
@SuppressWarnings("deprecation") public static void load(Context context) { IsFirstStart = mPrefs.getBoolean("IsFirstStart", true); Zoom = mPrefs.getFloat("Zoom", Float.NEGATIVE_INFINITY); Longitude = mPrefs.getDouble("Longitude", Double.NEGATIVE_INFINITY); Latitude = mPrefs.getDouble("Latitude", Double.NEGATIVE_INFINITY); UserNickName = mPrefs.getObject("UserNickName"); UserBikeType = mPrefs.getObject("UserBikeType"); MapType = mPrefs.getInt("MapType", BaiduMap.MAP_TYPE_NORMAL); HasCompass = mPrefs.getBoolean("HasCompass", DeviceHelper.isSensorExisted(context, Sensor.TYPE_ORIENTATION)); UseCompass = mPrefs.getBoolean("UseCompass", HasCompass); RouteColor = mPrefs.getInt("RouteColor", 0xFF00FF00); }
private void loadMapType() { TextView mapTypeView = (TextView) findViewById(R.id.map_type); String[] mapTypes = getResources().getStringArray(R.array.map_types); switch (Config.MapType) { case BaiduMap.MAP_TYPE_NORMAL: mapTypeView.setText(mapTypes[0]); break; case BaiduMap.MAP_TYPE_SATELLITE: mapTypeView.setText(mapTypes[1]); break; } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search); //接收所在位置的经纬度和位置信息 intent=getIntent(); address=intent.getStringExtra("address"); lLat=intent.getDoubleExtra("Lat", 0.1); lLng=intent.getDoubleExtra("Lng",0.1); //初始化地图控件 mMapView = (MapView) findViewById(R.id.mapview_location); mBaiduMap = mMapView.getMap(); mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL); //在地图上定位 add= (TextView) findViewById(R.id.tv_add); iv_add= (ImageView) findViewById(R.id.iv_add); iv_back= (ImageView) findViewById(R.id.iv_back); iv_back.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); add.setText(address); showMap(lLat, lLng); //初始化POI控件 mPoiSearch = PoiSearch.newInstance(); mPoiSearch.setOnGetPoiSearchResultListener(this); }
/** * 设置百度地图属性 */ private void setupBaiduMap() { bmapView.showZoomControls(false); //移除地图缩放控件 bmapView.removeViewAt(1); //移除百度地图Logo mBaiduMap = bmapView.getMap(); mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL); mBaiduMap.setMapStatus(MapStatusUpdateFactory.zoomTo(16)); mBaiduMap.getUiSettings().setOverlookingGesturesEnabled(false); //取消俯视手势 }
@Override public void onReceiveLocation(BDLocation location) { final BaiduMap map = getBaiduMap(); if (map == null || location == null || getActivity() == null) return; if (mPanMode.get() == AutoPanMode.USER) { updateBDMapStatus(location); } notifyToLocatorActivity(location); }
@Override public void clearAll(){ clearMarkers(); clearPolylines(); clearFlightPath(); clearMissionPath(); clearFootPrints(); clearPolygonPaths(); clearDroneLeashPath(); BaiduMap map = getBaiduMap(); if(map != null){ map.clear(); } }
private void updateCamera(final LatLong coord) { final BaiduMap map = getBaiduMap(); if ( map != null && coord != null) { final float zoomLevel = map.getMapStatus().zoom; map.animateMapStatus(MapStatusUpdateFactory.newLatLngZoom(MapUtils.coordToBaiduLatLng(coord), zoomLevel)); } }
@Override public void updateCamera(final LatLong coord, final float zoomLevel) { final BaiduMap map = getBaiduMap(); if ( map != null && coord != null) { map.animateMapStatus(MapStatusUpdateFactory.newLatLngZoom(MapUtils.coordToBaiduLatLng(coord), zoomLevel)); } }
@Override public void updateCameraBearing(float bearing) { final BaiduMap map = getBaiduMap(); if (map == null) return; final MapStatus.Builder camera = new MapStatus.Builder(map.getMapStatus()); camera.rotate(bearing); map.animateMapStatus(MapStatusUpdateFactory.newMapStatus(camera.build())); }
/** * Save the map camera state on a preference file * http://stackoverflow.com/questions * /16697891/google-maps-android-api-v2-restoring * -map-state/16698624#16698624 */ @Override public void saveCameraPosition() { final BaiduMap map = getBaiduMap(); if (map == null) return; final MapStatus mapStatus = map.getMapStatus(); mAppPrefs.prefs.edit() .putFloat(PREF_LAT, (float) mapStatus.target.latitude) .putFloat(PREF_LNG, (float) mapStatus.target.longitude) .putFloat(PREF_BEA, mapStatus.rotate) .putFloat(PREF_TILT, mapStatus.overlook) .putFloat(PREF_ZOOM, mapStatus.zoom).apply(); }