private void drawTrailLines(List<LatLng> pointList) { baiduMap.clear(); //把地图移动到point点 moveToLocation(pointList.get(pointList.size() / 2)); //绘制跑步开始标记 if (!pointList.isEmpty()) { addMarker(pointList.get(0), R.drawable.ic_loc_start); } //绘制跑步结束标记 if (!pointList.isEmpty()) { addMarker(pointList.get(pointList.size() - 1), R.drawable.ic_loc_end); } //画路径线 PolylineOptions polyline; if (pointList.size() >= 2 && pointList.size() < 10000) { polyline = new PolylineOptions() .width(6) .color(ContextCompat.getColor(this, R.color.colorPrimary)) .zIndex(0) .points(pointList); baiduMap.addOverlay(polyline);//添加Marker } }
/** * 画出实时线路点 * * @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 onMapReady(GoogleMap googleMap) { // Instantiates a new Polyline object and adds points to define a rectangle com.google.android.gms.maps.model.PolylineOptions rectOptions = new com.google.android.gms.maps.model.PolylineOptions() .add(new com.google.android.gms.maps.model.LatLng(-18.5186650000, 141.9748780000)) .add(new com.google.android.gms.maps.model.LatLng(-18.5186650000, 144.9748780000)) // North of the previous point, but at the same longitude .add(new com.google.android.gms.maps.model.LatLng(-20.5186650000, 144.9748780000)) // Same latitude, and 30km to the west .add(new com.google.android.gms.maps.model.LatLng(-20.5186650000, 141.9748780000)) // Same longitude, and 16km to the south .add(new com.google.android.gms.maps.model.LatLng(-24.5186650000, 141.9748780000)); // Closes the polyline. rectOptions.width(8) .color(ContextCompat.getColor(getActivity(), R.color.red_500)); // Get back the mutable Polyline com.google.android.gms.maps.model.Polyline polyline = googleMap.addPolyline(rectOptions); googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new com.google.android.gms.maps.model.LatLng(-18.5186650000, 141.9748780000), 6)); }
@Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { switch (buttonView.getId()) { case R.id.switchLBSTrace: if (isChecked) { polylineMyTrace = new PolylineOptions(); refreshMapUI(); mlistener.toolbarOperateCloseTrackOrOpenColor(true); } else { mlistener.toolbarOperateCloseTrackOrOpenColor(false); } break; case R.id.switchLocation: if (isChecked) { baiduMap.setMyLocationConfigeration(new MyLocationConfiguration(MyLocationConfiguration.LocationMode.FOLLOWING, false, null)); baiduMap.animateMapStatus(MapStatusUpdateFactory.zoomTo(baiduMap.getMaxZoomLevel() - 2)); } else baiduMap.setMyLocationConfigeration(new MyLocationConfiguration(MyLocationConfiguration.LocationMode.NORMAL, false, null)); break; } }
@Override public final List<OverlayOptions> getOverlayOptions() { if (mBusLineResult == null || mBusLineResult.getStations() == null) { return null; } List<OverlayOptions> overlayOptionses = new ArrayList<OverlayOptions>(); for (BusLineResult.BusStation station : mBusLineResult.getStations()) { overlayOptionses.add(new MarkerOptions() .position(station.getLocation()) .zIndex(10) .anchor(0.5f, 0.5f) .icon(BitmapDescriptorFactory .fromAssetWithDpi("Icon_bus_station.png"))); } List<LatLng> points = new ArrayList<LatLng>(); for (BusLineResult.BusStep step : mBusLineResult.getSteps()) { if (step.getWayPoints() != null) { points.addAll(step.getWayPoints()); } } if (points.size() > 0) { overlayOptionses .add(new PolylineOptions().width(10) .color(Color.argb(178, 0, 78, 255)).zIndex(0) .points(points)); } return overlayOptionses; }
/** * 画出实时线路点 * * @param point 最新线路点 */ private void drawCurrentPoint(LatLng point) { baiduMap.clear(); //把地图移动到point点 moveToLocation(point); //绘制跑步开始标记 if (!pointList.isEmpty()) { addMarker(pointList.get(0), R.drawable.ic_loc_start); } //画定位图标 if (runningStatus == 2) { addMarker(point, R.drawable.ic_loc_end); } else { addMarker(point, R.drawable.ic_loc_normal); } //画路径线 polyline = null; if (pointList.size() >= 2 && pointList.size() < 10000) { polyline = new PolylineOptions() .width(6) .color(ContextCompat.getColor(this, R.color.colorPrimary)) .zIndex(0) .points(pointList); baiduMap.addOverlay(polyline);//添加Marker } else if (pointList.size() >= 10000) { startButton.callOnClick(); new AlertDialog.Builder(this) .setTitle("超时提示") .setMessage(R.string.over_time) .setPositiveButton(R.string.got_it, null) .create().show(); } }
@Override public void addPolyline(final PolylineInfo polylineInfo) { if (polylineInfo == null || polylineInfo.isOnMap()) { return; } final PolylineOptions options = fromPolylineInfo(polylineInfo); if (options == null) { return; } Polyline polyline = (Polyline) getBaiduMap().addOverlay(options); polylineInfo.setProxyPolyline(new ProxyMapPolyline(polyline)); polylinesMap.put(polyline, polylineInfo); }
private PolylineOptions fromPolylineInfo(PolylineInfo info) { List<LatLng> points = MapUtils.coordToBaiduLatLng(info.getPoints()); if (points.size() <= 1) { return null; } return new PolylineOptions() .points(points) .color(info.getColor()) .visible(info.isVisible()) .width((int) info.getWidth()) .zIndex((int) info.getZIndex()); }
public void addCustomElementsDemo(LatLng latLng1, LatLng latLng2) { List<LatLng> points = new ArrayList<LatLng>(); points.add(latLng1); points.add(latLng2); OverlayOptions ooPolyline = new PolylineOptions().width(10) .color(0xAAFF0000).points(points); mBaiduMap.addOverlay(ooPolyline); }
public void addCustomEleemntsDemo(List<LatLng> latLngList) { List<LatLng> points = new ArrayList<LatLng>(); points.addAll(latLngList); OverlayOptions ooPolyline = new PolylineOptions().width(10) .color(0xAAFF0000).points(points); mBaiduMap.addOverlay(ooPolyline); }
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_route_detail); setStatusBar(); route_detail_mapview = (MapView) findViewById(R.id.route_detail_mapview); total_time = (TextView) findViewById(R.id.total_time); total_distance = (TextView) findViewById(R.id.total_distance); total_price = (TextView) findViewById(R.id.total_pricce); routeBaiduMap = route_detail_mapview.getMap(); route_detail_mapview.showZoomControls(false); startBmp = BitmapDescriptorFactory.fromResource(R.mipmap.route_start); endBmp = BitmapDescriptorFactory.fromResource(R.mipmap.route_end); initMap(); Intent intent = getIntent(); String time = intent.getStringExtra("totalTime"); String distance = intent.getStringExtra("totalDistance"); String price = intent.getStringExtra("totalPrice"); routePointsStr = intent.getStringExtra("routePoints"); routePoints = new Gson().fromJson(routePointsStr, new TypeToken<List<RoutePoint>>() { }.getType()); List<LatLng> points = new ArrayList<LatLng>(); for (int i = 0; i < routePoints.size(); i++) { RoutePoint point = routePoints.get(i); LatLng latLng = new LatLng(point.getRouteLat(), point.getRouteLng()); Log.d("gaolei", "point.getRouteLat()----show-----" + point.getRouteLat()); Log.d("gaolei", "point.getRouteLng()----show-----" + point.getRouteLng()); points.add(latLng); } if (points.size() > 2) { OverlayOptions ooPolyline = new PolylineOptions().width(10) .color(0xFF36D19D).points(points); routeBaiduMap.addOverlay(ooPolyline); RoutePoint startPoint = routePoints.get(0); LatLng startPosition = new LatLng(startPoint.getRouteLat(), startPoint.getRouteLng()); MapStatus.Builder builder = new MapStatus.Builder(); builder.target(startPosition).zoom(18.0f); routeBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); RoutePoint endPoint = routePoints.get(routePoints.size() - 1); LatLng endPosition = new LatLng(endPoint.getRouteLat(), endPoint.getRouteLng()); addOverLayout(startPosition, endPosition); } total_time.setText("骑行时长:" + time + "分钟"); total_distance.setText("骑行距离:" + distance + "米"); total_price.setText("余额支付:" + price + "元"); }
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_route_detail); route_detail_mapview = (MapView) findViewById(R.id.route_detail_mapview); total_time = (TextView) findViewById(R.id.total_time); total_distance = (TextView) findViewById(R.id.total_distance); total_price = (TextView) findViewById(R.id.total_pricce); routeBaiduMap = route_detail_mapview.getMap(); route_detail_mapview.showZoomControls(false); startBmp = BitmapDescriptorFactory.fromResource(R.mipmap.route_start); endBmp = BitmapDescriptorFactory.fromResource(R.mipmap.route_end); initMap(); Intent intent = getIntent(); String time = intent.getStringExtra("totalTime"); String distance = intent.getStringExtra("totalDistance"); String price = intent.getStringExtra("totalPrice"); routePointsStr = intent.getStringExtra("routePoints"); routePoints = new Gson().fromJson(routePointsStr, new TypeToken<List<RoutePoint>>() { }.getType()); savaDatas(time,distance,price);//yiwen add List<LatLng> points = new ArrayList<LatLng>(); for (int i = 0; i < routePoints.size(); i++) { RoutePoint point = routePoints.get(i); LatLng latLng = new LatLng(point.getRouteLat(), point.getRouteLng()); Log.d("gaolei", "point.getRouteLat()----show-----" + point.getRouteLat()); Log.d("gaolei", "point.getRouteLng()----show-----" + point.getRouteLng()); points.add(latLng); } if (points.size() > 2) { OverlayOptions ooPolyline = new PolylineOptions().width(10) .color(0xFF36D19D).points(points); routeBaiduMap.addOverlay(ooPolyline); RoutePoint startPoint = routePoints.get(0); LatLng startPosition = new LatLng(startPoint.getRouteLat(), startPoint.getRouteLng()); MapStatus.Builder builder = new MapStatus.Builder(); builder.target(startPosition).zoom(18.0f); routeBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); RoutePoint endPoint = routePoints.get(routePoints.size() - 1); LatLng endPosition = new LatLng(endPoint.getRouteLat(), endPoint.getRouteLng()); addOverLayout(startPosition, endPosition); } total_time.setText("骑行时长:" + time + "分钟"); total_distance.setText("骑行距离:" + distance + "米"); total_price.setText("余额支付:" + price + "元"); }
/** * 加载轨迹数据至百度地图 */ private void showBaiduMap(List<LocationDetail> locationDetails) { if (locationDetails == null || locationDetails.size() == 0) return; int countInCircle = 0; List<LatLng> polylines = new ArrayList<>(); for (LocationDetail locationDetail : locationDetails) { if (locationDetail.isInvalid()) continue; LatLng lng = locationDetail.getLatLng(); polylines.add(lng); if (polylines.size() > 1) { if (SpatialRelationUtil.isCircleContainsPoint(polylines.get(0), LOCATION_RADIUS, lng)) { countInCircle++; } } } Collections.reverse(polylines); //按时间正序 OverlayOptions markerOptions = null; if (polylines.size() > 1) { OverlayOptions polylineOptions = new PolylineOptions() .points(polylines) .width(8) .color(ContextCompat.getColor(getActivity(), R.color.red_500)); mVirtureRoad = (Polyline) mBaiduMap.addOverlay(polylineOptions); markerOptions = new MarkerOptions().flat(true).anchor(0.5f, 0.5f).icon(BitmapDescriptorFactory .fromResource(R.drawable.ic_car)).position(polylines.get(0)).rotate((float) getAngle(0)); } else { markerOptions = new MarkerOptions().flat(true).anchor(0.5f, 0.5f).icon(BitmapDescriptorFactory .fromResource(R.drawable.ic_car)).position(polylines.get(0)); } mMoveMarker = (Marker) mBaiduMap.addOverlay(markerOptions); //设置中心点 setBaiduMapAdaptedZoom(polylines); if (polylines.size() > 1 && countInCircle < polylines.size() / 2) { movingThread = new Thread(new MyThread()); movingThread.start(); } }
@Override public void showBaiduMap(List<LocationDetail> locationDetails) { if (locationDetails == null || locationDetails.size() == 0) return; int countInCircle = 0; List<LatLng> polylines = new ArrayList<>(); for (LocationDetail locationDetail : locationDetails) { if (locationDetail.isInvalid()) continue; LatLng lng = locationDetail.getLatLng(); polylines.add(lng); if (polylines.size() > 1) { if (SpatialRelationUtil.isCircleContainsPoint(polylines.get(0), LOCATION_RADIUS, lng)) { countInCircle++; } } } Collections.reverse(polylines); //按时间正序 OverlayOptions markerOptions = null; if (polylines.size() > 1) { OverlayOptions polylineOptions = new PolylineOptions() .points(polylines) .width(8) .color(ContextCompat.getColor(getActivity(), R.color.red_500)); mVirtureRoad = (Polyline) mBaiduMap.addOverlay(polylineOptions); markerOptions = new MarkerOptions().flat(true).anchor(0.5f, 0.5f).icon(BitmapDescriptorFactory .fromResource(R.drawable.ic_car)).position(polylines.get(0)).rotate((float) getAngle(0)); } else { markerOptions = new MarkerOptions().flat(true).anchor(0.5f, 0.5f).icon(BitmapDescriptorFactory .fromResource(R.drawable.ic_car)).position(polylines.get(0)); } mMoveMarker = (Marker) mBaiduMap.addOverlay(markerOptions); //设置中心点 setBaiduMapAdaptedZoom(polylines); if (polylines.size() > 1 && countInCircle < polylines.size() / 2) { movingThread = new Thread(new MyThread()); movingThread.start(); } }
@Override public void onReceive(Context context, Intent intent) { switch (intent.getAction()) { //实时位置信息收到广播 case "cc.bitlight.broadcast.location.data": { NavigationViewItemLocateMode.setTitle("定位方式:" + application.getLocateMode()); NavigationViewItemLongitude.setTitle("经度:" + application.getLongitude()); NavigationViewItemLatitude.setTitle("纬度:" + application.getLatitude()); NavigationViewItemRadius.setTitle("精度:" + application.getRadius() + "米"); tvNavigationViewHeaderAddress.setText("当前位置:" + application.getAddress()); MyLocationData locData = new MyLocationData.Builder() .accuracy(application.getRadius()) .latitude(application.getLatitude()) .longitude(application.getLongitude()).build(); // 设置定位数据 mapFragment.setBaiduMapLocationData(locData); Log.d("lml", "location.data接收到"); } break; //实时周边信息收到广播 case "cc.bitlight.broadcast.nearbyinfo.data": { List<MyRadarNearbyInfo> myRadarNearbyInfoList = application.getMyRadarNearbyInfoList(); int infoListSize = myRadarNearbyInfoList.size(); nearbyFragment.setRadarNearbyInfoList(myRadarNearbyInfoList, infoListSize); mapFragment.setRadarNearbyInfoList(myRadarNearbyInfoList, infoListSize); Log.d("lml", "nearbyinfo.data接收到 ;" + "NearbyFragment:输出尺寸list.size():" + infoListSize); Message message = new Message(); message.what = MESSAGE_LOGIN_SUCCEED; handler.sendMessage(message); } break; //历史轨迹信息收到并请求绘制广播 case "cc.bitlight.broadcast.track.historytrack.draw": { Log.d("lml", "track.historytrack.draw收到" + intent.getDoubleExtra("distance", 0)); int distance = (int) intent.getDoubleExtra("distance", 0); NavigationViewItemTrackQuery.setTitle("轨迹查询:共" + distance + "米"); mapFragment.polylineHistoryTrace = new PolylineOptions(); mapFragment.refreshMapUI(); toolbarOperateCloseTrackOrOpenColor(true);//标红toolbar中轨迹清除按钮 } break; case "cc.bitlight.broadcast.geofence.reload": menuToolbarItemGeoFenceStatus.setTitle("围栏已开启"); menuToolbarItemGeoFenceStatus.setIcon(R.mipmap.menu_toolbar_ic_geofence_on); int radius = intent.getIntExtra("radius", 0); LatLng latLng = new LatLng(intent.getDoubleExtra("latitude", 0), intent.getDoubleExtra("longitude", 0)); mapFragment.createOrUpdateFenceShow(radius, latLng); break; case "cc.bitlight.broadcast.geofence.notification": String userID = intent.getStringExtra("userID"); int fenceStatus = intent.getIntExtra("fenceStatus", 0); if (fenceStatus == 1) { snackbar = Snackbar.make(coordinatorLayoutContainer, "用户\"" + userID + "\"已进入了指定范围", Snackbar.LENGTH_LONG); snackbar.setAction("查看详情", new View.OnClickListener() { @Override public void onClick(View v) { vp_FindFragment_pager.setCurrentItem(1); } }); snackbar.show(); } if (fenceStatus == 2) { snackbar = Snackbar.make(coordinatorLayoutContainer, "用户\"" + userID + "\"已离开了指定范围", Snackbar.LENGTH_LONG); snackbar.show(); } break; } }
@Override public Polyline addPolylineWithPoints(List<LatLng> points) { OverlayOptions option = new PolylineOptions().points(points).zIndex(999); Polyline polyline = (Polyline) mBaiduMap.addOverlay(option); return polyline; }
/** 绘制历史轨迹 * * @param points */ private void drawHistoryTrack(final List<LatLng> points,final double distance) { // 绘制新覆盖物前,清空之前的覆盖物 mBaiduMap.clear(); if(points.size() == 1){ points.add(points.get(0)); } if(points == null || points.size() == 0){ TrackApplication.showMessage("当前查询无轨迹点"); resetMarker(); }else if (points.size() > 1) { LatLng llc = points.get(0); LatLng llD = points.get(points.size() - 1); LatLngBounds bounds = new LatLngBounds.Builder() .include(llc).include(llD).build(); mapStatusUpdate = MapStatusUpdateFactory.newLatLngBounds(bounds); //起点图标 bmStart = BitmapDescriptorFactory.fromResource(R.drawable.icon_start); bmEnd = BitmapDescriptorFactory.fromResource(R.drawable.icon_end); //添加起点图标 startMarker = new MarkerOptions() .position(points.get(points.size() - 1)).icon(bmStart) .zIndex(9).draggable(true); //添加终点图标 endMarker = new MarkerOptions().position(points.get(0)) .icon(bmEnd).zIndex(9).draggable(true); //添加路线 polylineOptions = new PolylineOptions().width(10) .color(Color.RED).points(points); markerOptions = new MarkerOptions(); markerOptions.flat(true); markerOptions.anchor(0.5f, 0.5f); markerOptions.icon(BitmapDescriptorFactory .fromResource(R.drawable.icon_gcoding)); markerOptions.position(points.get(points.size() - 1)); addMarker(); } }