private void cancelBook() { countDownTimer.cancel(); bike_layout.setVisibility(View.GONE); bike_info_layout.setVisibility(View.GONE); confirm_cancel_layout.setVisibility(View.GONE); prompt.setVisibility(View.GONE); bike_distance_layout.setVisibility(View.VISIBLE); bike_distance_layout.setVisibility(View.VISIBLE); book_bt.setVisibility(View.VISIBLE); if (routeOverlay != null) routeOverlay.removeFromMap(); MapStatus.Builder builder = new MapStatus.Builder(); //地图缩放比设置为18 builder.target(currentLL).zoom(18.0f); mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); }
@Override public void zoomToSpan() { if (mAmosfMap != null) { try { mAmosfMap.postDelayed(new Runnable() { @Override public void run() { ConfirmCustomPoiOverlay.super.zoomToSpan(); if (mAmosfPoiBox.getVisibility() == View.VISIBLE) { MapStatus ms = baiduMap.getMapStatus(); ms.targetScreen.set(ScreenUtil.getInstance().getWidthPixels() / 2, ScreenUtil.getInstance().getHeightPixels() / 4); baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(ms)); } } }, 300); } catch (Exception e) { e.printStackTrace(); } } }
@Override public void zoomToSpan() { if (mAmosfMap != null) { try { mAmosfMap.postDelayed(new Runnable() { @Override public void run() { ConfirmPoiOverlay.super.zoomToSpan(); if (mAmosfPoiBox.getVisibility() == View.VISIBLE) { MapStatus ms = baiduMap.getMapStatus(); ms.targetScreen.set(ScreenUtil.getInstance().getWidthPixels() / 2, ScreenUtil.getInstance().getHeightPixels() / 4); baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(ms)); } } }, 300); } catch (Exception e) { e.printStackTrace(); } } }
@Override public void zoomToSpan() { if (mAncpMap != null) { try { mAncpMap.postDelayed(new Runnable() { @Override public void run() { ConfirmCustomPoiOverlay.super.zoomToSpan(); if (mAncpPoiBox.getVisibility() == View.VISIBLE) { MapStatus ms = baiduMap.getMapStatus(); ms.targetScreen.set(ScreenUtil.getInstance().getWidthPixels() / 2, ScreenUtil.getInstance().getHeightPixels() / 4); baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(ms)); } } }, 500); } catch (Exception e) { e.printStackTrace(); } } }
/** * 缩放地图,使所有Overlay都在合适的视野内 **/ @Override public void zoomToSpan() { if (mAncpMap != null) { try { mAncpMap.postDelayed(new Runnable() { @Override public void run() { ConfirmPoiOverlay.super.zoomToSpan(); if (mAncpPoiBox.getVisibility() == View.VISIBLE) { MapStatus ms = baiduMap.getMapStatus(); /* 设置地图操作中心点在屏幕中的坐标 */ ms.targetScreen.set(ScreenUtil.getInstance().getWidthPixels() / 2, ScreenUtil.getInstance().getHeightPixels() / 4); /* 以动画的方式更新地图状态,耗时300ms */ baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(ms)); } } }, 500); } catch (Exception e) { e.printStackTrace(); } } }
@Override public void zoomToSpan() { if (mapView != null) { try { mapView.postDelayed(new Runnable() { @Override public void run() { ConfirmPoiOverlay.super.zoomToSpan(); if (mTrafficShowView.getPoiListBox().getVisibility() == View.VISIBLE) { MapStatus ms = baiduMap.getMapStatus(); ms.targetScreen.set(ScreenUtil.getInstance().getWidthPixels() / 2, ScreenUtil.getInstance().getHeightPixels() / 4); baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(ms)); } } }, 300); } catch (Exception e) { e.printStackTrace(); } } }
@Override public void zoomToSpan() { if (mapView != null) { try { mapView.postDelayed(new Runnable() { @Override public void run() { ConfirmCustomPoiOverlay.super.zoomToSpan(); if (mTrafficShowView.getPoiListBox().getVisibility() == View.VISIBLE) { MapStatus ms = baiduMap.getMapStatus(); ms.targetScreen.set(ScreenUtil.getInstance().getWidthPixels() / 2, ScreenUtil.getInstance().getHeightPixels() / 4); baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(ms)); } } }, 300); } catch (Exception e) { e.printStackTrace(); } } }
private void stopRunning() { runningStatus = 2; timer.stop(); client.stop(); startButton.setIdleText("跑步结束"); startButton.setProgress(0); if (!pointList.isEmpty()) { addMarker(pointList.get(pointList.size() - 1), R.drawable.ic_loc_end); } msUpdate = MapStatusUpdateFactory.newMapStatus( new MapStatus.Builder().zoom(17).build() ); baiduMap.setMapStatus(msUpdate); locTimes = 0;//重置定位次数 stepSensor.unregisterStep(); saveRunData(); // 计算平均速度 float speed = Integer.parseInt(distanceNumber.getNumber()) / getSeconds(); speedNumber.setText(Utility.formatDecimal(speed, 2)); }
@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 public void onMapStatusChangeFinish(MapStatus mapStatus) { // int size = mMarkerManager.getCollectionSize(); mZoom = mBaiduMap.getMapStatus().zoom; // if(mZoom <=12.4f){ // mBaiduMap.clear(); // isShow = false; // } if(mZoom <= 11f){ mBaiduMap.clear(); isShow = false; } if(mZoom >= 11f && mZoom <=16.0f){ if(!isShow){ isShow = true; } //允许显示定位图层 mBaiduMap.setMyLocationEnabled(true); } }
@Override public void onReceiveLocation(BDLocation location) { // map view 销毁后不在处理新接收的位置 if (location == null || mMapView == null) { return; } mCurrentLat = location.getLatitude(); mCurrentLon = location.getLongitude(); mCurrentAccracy = location.getRadius(); locData = new MyLocationData.Builder() .accuracy(location.getRadius()) // 此处设置开发者获取到的方向信息,顺时针0-360 .direction(mCurrentDirection).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(18.0f); mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); } }
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_routeplan); mTvtitle = (TextView) findViewById(R.id.tv_topbar_title); mTvtitle.setText("财神谷地址"); ImageView img = (ImageView) findViewById(R.id.img_topbar_back); img.setImageResource(R.mipmap.icon_back); img.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { RoutePlanDemo.this.finish(); } }); // mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);//获取传感器管理服务 // 初始化地图 mMapView = (MapView) findViewById(R.id.map); mBaidumap = mMapView.getMap(); MapStatus.Builder builder = new MapStatus.Builder(); builder.zoom(18.0f); builder.target(new LatLng(29.184662, 121.305024)); mMapStatusUpdate = MapStatusUpdateFactory.newMapStatus(builder.build()); mBaidumap.setMapStatus(mMapStatusUpdate); MarkerOptions ooA = new MarkerOptions().position(GEO_NINGBO).icon(bdA) .zIndex(9).draggable(true); mBaidumap.addOverlay(ooA); mBaidumap.setTrafficEnabled(true); findViewById(R.id.lin_action_route).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { go2ThirdMap(); } }); }
public void onMapStatusChangeFinish(MapStatus mapStatus) { String _str = mapStatus.toString(); String _regex = "target lat: (.*)\ntarget lng"; String _regex2 = "target lng: (.*)\ntarget screen x"; changeLatitude = Double.parseDouble(latlng(_regex, _str)); changeLongitude = Double.parseDouble(latlng(_regex2, _str)); LatLng changeLL = new LatLng(changeLatitude, changeLongitude); startNodeStr = PlanNode.withLocation(changeLL); Log.d(TAG, "changeLatitude-----change--------" + changeLatitude); Log.d(TAG, "changeLongitude-----change--------" + changeLongitude); if (!isNeedCurrentlocation) { MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(changeLL); baiduMap.setMapStatus(u); if (Math.hypot((changeLatitude - currentLatitude), (changeLongitude - currentLongitude)) > 0.00001) { Logger.d(Math.hypot((changeLatitude - currentLatitude), (changeLongitude - currentLongitude))); if (routeOverlay != null) routeOverlay.removeFromMap(); addOverLayout(changeLatitude, changeLongitude); } } }
private void cancelBook() { if (isNeedLogin) { mLogin.setVisibility(View.VISIBLE); } else { mLogin.setVisibility(View.GONE); } mBikeInfoBoard.setVisibility(View.GONE); countDownTimer.cancel(); mBikeOrderBoard.setVisibility(View.GONE); // confirm_cancel_layout.setVisibility(View.GONE); // prompt.setVisibility(View.GONE); // bike_distance_layout.setVisibility(View.VISIBLE); // bike_distance_layout.setVisibility(View.VISIBLE); mBtLoginOrorder.setVisibility(View.VISIBLE); if (routeOverlay != null) routeOverlay.removeFromMap(); MapStatus.Builder builder = new MapStatus.Builder(); //地图缩放比设置为18 builder.target(currentLL).zoom(18.0f); baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); }
/** * 画出实时线路点 * * @param point */ private void drawRealtimePoint(LatLng point) { Log.i("TGA", "绘制成功"); mBaiduMap.clear(); MapStatus mapStatus = new MapStatus.Builder().target(point).zoom(18).build(); msUpdate = MapStatusUpdateFactory.newMapStatus(mapStatus); realtimeBitmap = BitmapDescriptorFactory.fromResource(R.drawable.ct_map_location); overlay = new MarkerOptions().position(point) .icon(realtimeBitmap).zIndex(9).draggable(true); if (pointList.size() >= 2 && pointList.size() <= 6000) { polyline = new PolylineOptions().width(10).color(Color.GREEN).points(pointList); } addMarker(); }
@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(100).latitude(location.getLatitude()) .longitude(location.getLongitude()).build(); mBaiduMap.setMyLocationData(locData); if (isFirstLoc) { isFirstLoc = false; LatLng ll = new LatLng(location.getLatitude(), location.getLongitude()); applicate=(Myapplication)getApplication(); applicate.setLon(location.getLongitude()); applicate.setLat(location.getLatitude()); MapStatus.Builder builder = new MapStatus.Builder(); builder.target(ll).zoom(18.0f); mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); } }
private void initViews() { mBtnPre = (Button) findViewById(R.id.btn_busline_pre); mBtnNext = (Button) findViewById(R.id.btn_busline_next); mBtnPre.setVisibility(View.INVISIBLE); mBtnNext.setVisibility(View.INVISIBLE); etRouteOnline = (EditText) findViewById(R.id.et_route_online); mBaiduMap = ((SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.bmapView)).getBaiduMap(); // �趨��ͼ��ʼ���ĵ����꣨�����ʵ��ѧ����У���� LatLng xayd = new LatLng(34.162719, 108.907775); // �趨��ͼ״̬���趨��ʼ���ĵ�����ż����� MapStatus mMapStatus = new MapStatus.Builder().target(xayd).zoom(12) .build(); // ����MapStatusUpdate�����Ա�������ͼ״̬��Ҫ�����ı仯 MapStatusUpdate mMapStatusUpdate = MapStatusUpdateFactory .newMapStatus(mMapStatus); // ���õ�ͼ״̬ mBaiduMap.setMapStatus(mMapStatusUpdate); }
private void setMapView() { BaiduMapOptions options = new BaiduMapOptions(); options.compassEnabled(false); options.overlookingGesturesEnabled(false); options.rotateGesturesEnabled(false); options.scaleControlEnabled(true); options.zoomControlsEnabled(false); MapStatus.Builder status = new MapStatus.Builder(); if (Config.Zoom > Float.NEGATIVE_INFINITY) status.zoom(Config.Zoom); if (Config.Latitude > Double.NEGATIVE_INFINITY && Config.Longitude > Double.NEGATIVE_INFINITY) status.target(new LatLng(Config.Latitude, Config.Longitude)); options.mapStatus(status.build()); mMapView = new MapView(this, options); mMapView.getMap().setMyLocationEnabled(true); mMapView.getMap().setBuildingsEnabled(false); mMapView.getMap().setOnMapStatusChangeListener(this); MapViewUtils.initViewPositions(mMapView); MapViewUtils.addMapView(this, mMapView); }
private void initBaiduMap() { mBaiduMap = mIMapView.getBaiduMap(); //获取地图对象控制器 mBaiduMap.setBuildingsEnabled(true);//设置显示楼体 mBaiduMap.setMapStatus(MapStatusUpdateFactory.zoomTo(19f));//设置地图状态 mUiSettings = mBaiduMap.getUiSettings(); mUiSettings.setZoomGesturesEnabled(true); mUiSettings.setScrollGesturesEnabled(true); mUiSettings.setRotateGesturesEnabled(true); mUiSettings.setOverlookingGesturesEnabled(true); mUiSettings.setCompassEnabled(true); MapStatus ms = new MapStatus.Builder().overlook(30).build(); MapStatusUpdate u = MapStatusUpdateFactory.newMapStatus(ms); mBaiduMap.animateMapStatus(u, 1000); // 初始化搜索模块 mSearch = GeoCoder.newInstance(); mSearch.setOnGetGeoCodeResultListener(this); }
@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())); }
/** * 初始化地图 */ private void initMapView() { //设定中心点坐标 myLatLng = new LatLng(Const.LATITUDE_OF_MY_LOCATION,Const.LONGITUDE_OF_MY_LOCATION); //定义地图状态 MapStatus mMapStatus = new MapStatus.Builder() .target(myLatLng) .zoom(18) .build(); //定义MapStatusUpdate对象,以便描述地图状态将要发生的变化 bd = BitmapDescriptorFactory .fromResource(R.drawable.icon_gcoding); MarkerOptions markerOptions = new MarkerOptions().position(myLatLng).icon(bd); mBaiduMap.addOverlay(markerOptions); MapStatusUpdate mMapStatusUpdate = MapStatusUpdateFactory.newMapStatus(mMapStatus); //改变地图状态 mBaiduMap.setMapStatus(mMapStatusUpdate); }
@Override public void onReceiveLocation(BDLocation location) { // map view 销毁后不在处理新接收的位置 if (location == null || mapView == null) { return; } tvLocation.setText(location.getAddrStr()); MyLocationData locData = new MyLocationData.Builder() .accuracy(location.getRadius()) // 此处设置开发者获取到的方向信息,顺时针0-360 .direction(100).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(18.0f); mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); } }
/** * 切换路线图标,刷新地图使其生效 * 注意: 起终点图标使用中心对齐. */ public void changeRouteIcon(View v) { if (useDefaultIcon) { ((Button) v).setText("跟随"); follow=true; LatLng ll = new LatLng(nowLocation.getLatitude(), nowLocation.getLongitude()); MapStatus.Builder builder = new MapStatus.Builder(); builder.target(ll).zoom(21.0f); mBaidumap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); } else { ((Button) v).setText("不跟随"); follow=false; } useDefaultIcon = !useDefaultIcon; /* routeOverlay.removeFromMap(); routeOverlay.addToMap();*/ }
@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); }
@Override public void onReceiveLocation(BDLocation bdLocation) { // map view 销毁后不在处理新接收的位置 if (bdLocation == null || mMapView == null) { return; } MyLocationData locData = new MyLocationData.Builder() .accuracy(bdLocation.getRadius()) .direction(mCurrentX)//设定图标方向 // 此处设置开发者获取到的方向信息,顺时针0-360 .latitude(bdLocation.getLatitude()) .longitude(bdLocation.getLongitude()).build(); mBaiduMap.setMyLocationData(locData); currentLatitude = bdLocation.getLatitude(); currentLongitude = bdLocation.getLongitude(); current_addr.setText(bdLocation.getAddrStr()); currentLL = new LatLng(bdLocation.getLatitude(), bdLocation.getLongitude()); LocationManager.getInstance().setCurrentLL(currentLL); LocationManager.getInstance().setAddress(bdLocation.getAddrStr()); startNodeStr = PlanNode.withLocation(currentLL); //option.setScanSpan(5000),每隔5000ms这个方法就会调用一次,而有些我们只想调用一次,所以要判断一下isFirstLoc if (isFirstLoc) { isFirstLoc = false; LatLng ll = new LatLng(bdLocation.getLatitude(), bdLocation.getLongitude()); MapStatus.Builder builder = new MapStatus.Builder(); //地图缩放比设置为18 builder.target(ll).zoom(18.0f); mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); changeLatitude = bdLocation.getLatitude(); changeLongitude = bdLocation.getLongitude(); if (!isServiceLive) { addOverLayout(currentLatitude, currentLongitude); } } }
public void onMapStatusChangeFinish(MapStatus mapStatus) { String _str = mapStatus.toString(); String _regex = "target lat: (.*)\ntarget lng"; String _regex2 = "target lng: (.*)\ntarget screen x"; changeLatitude = Double.parseDouble(latlng(_regex, _str)); changeLongitude = Double.parseDouble(latlng(_regex2, _str)); LatLng changeLL = new LatLng(changeLatitude, changeLongitude); startNodeStr = PlanNode.withLocation(changeLL); Log.d("gaolei", "changeLatitude-----change--------" + changeLatitude); Log.d("gaolei", "changeLongitude-----change--------" + changeLongitude); }
/** * 设置地图比例,保证所有poi点可视 **/ private void setPoiPosition() { if (aList.size() == 0 || poiOverlay == null) return; if (aList.size() == 1) { MapStatus.Builder builder = new MapStatus.Builder(); builder.target(new LatLng(aList.get(0).getLatitude(), aList.get(0).getLongitude())) .targetScreen(new Point(baiduMap.getMapStatus().targetScreen.x, baiduMap.getMapStatus().targetScreen.y / 4)) .zoom(17F); baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); } else poiOverlay.zoomToSpan(); }
/** * 设置检索结果显示索引(若有多个结果则地图缩放到保证所有结果可见) **/ private void setPoiPosition() { if (aList.size() == 0 || poiOverlay == null) return; if (aList.size() == 1) { MapStatus.Builder builder = new MapStatus.Builder(); builder.target(new LatLng(aList.get(0).getLatitude(), aList.get(0).getLongitude())) .targetScreen(new Point(baiduMap.getMapStatus().targetScreen.x, baiduMap.getMapStatus().targetScreen.y / 4)) .zoom(17F); baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); } else poiOverlay.zoomToSpan(); }
private void setPoiPosition() { if (aList.size() == 0 || poiOverlay == null) return; if (aList.size() == 1) { MapStatus.Builder builder = new MapStatus.Builder(); builder.target(new LatLng(aList.get(0).getLatitude(), aList.get(0).getLongitude())) .targetScreen(new Point(baiduMap.getMapStatus().targetScreen.x, baiduMap.getMapStatus().targetScreen.y / 4)) .zoom(17F); baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); } else poiOverlay.zoomToSpan(); }
@Override public void onReceiveLocation(BDLocation location) { if (null != location && location.getLocType() != BDLocation.TypeServerError) { mLatitude = location.getLatitude(); mLongitude = location.getLongitude(); mNearbyPersonPresenter.getNearbyPersons(mUserId,String.valueOf(mLongitude),String.valueOf(mLatitude),mSex); mBaiduMap.clear(); mBaiduMap.setMyLocationEnabled(false); //停止定位服务 mLocationService.stop(); //需要将mitems中的数据清空 if (mItems != null && mItems.size() > 0) { mItems.clear(); } //第一次定位到当前的位置 // 显示到定位的地方 //为了取消定位蓝点,设置了setMyLocationEnabled(false),所以下面的代码实际上不起作用 LatLng ll = new LatLng(location.getLatitude(), location.getLongitude()); MapStatus.Builder builder = new MapStatus.Builder(); builder.target(ll).zoom(16.0f); mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()), 300); } else { //定位失败就不继续定位了 // Toast.makeText(getActivity(), "定位失败,失败码是:" + location.getLocType(), Toast.LENGTH_SHORT).show(); Log.d("----", "onReceiveLocation: 定位失败,失败码是:"+location.getLocType()); } }
@Override public void onReceiveLocation(BDLocation bdLocation) { if (bdLocation == null || baiduMap == null) { return; } mBDLocation = bdLocation; MyLocationData locData = new MyLocationData.Builder() .accuracy(bdLocation.getRadius()) .direction(mCurrentX)//设定图标方向 // 此处设置开发者获取到的方向信息,顺时针0-360 .latitude(bdLocation.getLatitude()) .longitude(bdLocation.getLongitude()).build(); if (isNeedCurrentlocation) baiduMap.setMyLocationData(locData); currentLatitude = bdLocation.getLatitude(); currentLongitude = bdLocation.getLongitude(); mTvLocationInfo.setText(bdLocation.getAddrStr()); currentLL = new LatLng(bdLocation.getLatitude(), bdLocation.getLongitude()); MyLocationManager.getInstance().setCurrentLL(currentLL); MyLocationManager.getInstance().setAddress(bdLocation.getAddrStr()); startNodeStr = PlanNode.withLocation(currentLL); //option.setScanSpan(5000),每隔5000ms这个方法就会调用一次,而有些我们只想调用一次,所以要判断一下isFirstLoc if (isFirstLocation) { isFirstLocation = false; LatLng ll = new LatLng(bdLocation.getLatitude(), bdLocation.getLongitude()); MapStatus.Builder builder = new MapStatus.Builder(); //地图缩放比设置为18 builder.target(ll).zoom(18.0f); baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); changeLatitude = bdLocation.getLatitude(); changeLongitude = bdLocation.getLongitude(); if (!isServiceLive) { addOverLayout(currentLatitude, currentLongitude); } } }
@Override public void onGetGeoCodeResult(GeoCodeResult result) { if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) { DialogUtils.dissmissLoadDialog(); Toast.makeText(GeoCodeActivity.this, "抱歉,未能找到结果", Toast.LENGTH_LONG).show(); return; } mBaiduMap.clear(); mBaiduMap.addOverlay(new MarkerOptions().position(result.getLocation()).icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_marka))); mBaiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng(result.getLocation())); mBaiduMap.setMapStatus(MapStatusUpdateFactory.newMapStatus(new MapStatus.Builder().zoom(15).build())); String strInfo = String.format("查找成功!\n纬度:%f 经度:%f", result.getLocation().latitude, result.getLocation().longitude); DialogUtils.dissmissLoadDialog(); Toast.makeText(GeoCodeActivity.this, strInfo, Toast.LENGTH_LONG).show(); }
@Override public void onGetReverseGeoCodeResult(ReverseGeoCodeResult result) { if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) { Toast.makeText(GeoCodeActivity.this, "抱歉,未能找到结果", Toast.LENGTH_LONG).show(); return; } mBaiduMap.clear(); mBaiduMap.addOverlay(new MarkerOptions().position(result.getLocation()).icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_marka))); mBaiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng(result.getLocation())); mBaiduMap.setMapStatus(MapStatusUpdateFactory.newMapStatus(new MapStatus.Builder().zoom(15).build())); Toast.makeText(GeoCodeActivity.this, result.getAddress(), Toast.LENGTH_LONG).show(); }
@Override public void onReceiveLocation(BDLocation location) { // map view 销毁后不在处理新接收的位置 Log.d("wang","onReceiveLocation successfully"); if (location == null || mMapView == null) { return; } Log.d("wang","onReceiveLocation location is null"); MyLocationData locData = new MyLocationData.Builder() .accuracy(location.getRadius()) // 此处设置开发者获取到的方向信息,顺时针0-360 .direction(100).latitude(location.getLatitude()) .longitude(location.getLongitude()).build(); mBaiduMap.setMyLocationData(locData); //mMapView.refreshDrawableState(); if(latArray.size() != 0) { float[] distance = new float[1]; for(int i = 0; i < latArray.size();i++) { LatLng loc = latArray.get(i); Location.distanceBetween(loc.latitude, loc.longitude, location.getLatitude(), location.getLongitude(), distance); Log.d("wang","distance is " + distance[0]); if(distance[0] <= 2000.0){ toast("2000 distance is bigger " + Math.round(distance[0])); tts.speak("距离标记位置" + i + "还有" + Math.round(distance[0]) + "米", TextToSpeech.QUEUE_ADD, null); } else { //toast("200 distance is smaller " + distance[0]); } } } if (isFirstLoc) { isFirstLoc = false; LatLng ll = new LatLng(location.getLatitude(), location.getLongitude()); MapStatus.Builder builder = new MapStatus.Builder(); builder.target(ll).zoom(18.0f); mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); } }
private void initViews() { mBtnPre = (Button) findViewById(R.id.pre); mBtnNext = (Button) findViewById(R.id.next); mBtnPre.setVisibility(View.INVISIBLE); mBtnNext.setVisibility(View.INVISIBLE); etStart = (EditText) findViewById(R.id.et_online_transstart); etEnd = (EditText) findViewById(R.id.et_online_transend); // ��ʼ����ͼ mMapView = (MapView) findViewById(R.id.map); mBaidumap = mMapView.getMap(); // �趨��ͼ��ʼ���ĵ����꣨�����ʵ��ѧ����У���� LatLng xayd = new LatLng(34.162719, 108.907775); // �趨��ͼ״̬���趨��ʼ���ĵ�����ż����� MapStatus mMapStatus = new MapStatus.Builder().target(xayd).zoom(12) .build(); // ����MapStatusUpdate�����Ա�������ͼ״̬��Ҫ�����ı仯 MapStatusUpdate mMapStatusUpdate = MapStatusUpdateFactory .newMapStatus(mMapStatus); // ���õ�ͼ״̬ mBaidumap.setMapStatus(mMapStatusUpdate); // ��ʼ������ģ�飬ע���¼����� mSearch = RoutePlanSearch.newInstance(); }
private void showMap(double latitude, double longtitude) { LatLng point = new LatLng(latitude, longtitude); BitmapDescriptor bitmap = null; bitmap = BitmapDescriptorFactory.fromResource(R.mipmap.lock); OverlayOptions option = new MarkerOptions().position(point).icon(bitmap); // 在地图上添加Marker,并显示 mBaiduMap.addOverlay(option); mBaiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng(point)); //设置缩放级别为500米 mBaiduMap.setMapStatus(MapStatusUpdateFactory.newMapStatus(new MapStatus.Builder().zoom(15).build())); }
@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(); }
@Override public void updateCameraBearing(float bearing) { MapStatus ms = new MapStatus.Builder(getBaiduMap().getMapStatus()).rotate(bearing).build(); MapStatusUpdate u = MapStatusUpdateFactory.newMapStatus(ms); getBaiduMap().animateMapStatus(u); }