fix: 更新自动匹配算法
This commit is contained in:
parent
e592017769
commit
d830315c6b
@ -12,8 +12,8 @@ android {
|
||||
applicationId "com.navinfo.outdoor"
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 30
|
||||
versionCode 31
|
||||
versionName "8.221118"
|
||||
versionCode 32
|
||||
versionName "8.221125"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
lintOptions {
|
||||
|
@ -17,6 +17,7 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
@ -214,10 +215,11 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
|
||||
private Switch locationSwitch;
|
||||
private boolean locationEnable=true;
|
||||
private ImageView imgViewSettingHook; // 调起隐藏设置的按钮
|
||||
private TencentLocation oldCurrentLocation = null;
|
||||
private Point oldCurrentLocation = null; // 记录上一次的位置信息
|
||||
private MediaPlayer mediaPlayer;
|
||||
private ImageView imgNaviDistance; // 自动规划到距离最近的数据开关
|
||||
private ImageView imgNaviDistance/*自动规划到距离最近的数据开关*/, imgRoadDirection; // 道路方向匹配开关
|
||||
private Polyline currentNaviLine; // 当前界面上正显示的导航路径线,重绘路径时需要清除此前已绘制的路径
|
||||
private boolean startMatchEnableDirection = false; // 是否启用方向匹配起点
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@ -268,6 +270,7 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
|
||||
btnClearMatch = findViewById(R.id.clear_all_match_data);
|
||||
btnStopPicture = findViewById(R.id.btn_stop_picture);
|
||||
imgNaviDistance = findViewById(R.id.img_navi_distance);
|
||||
imgRoadDirection = findViewById(R.id.img_road_direction);
|
||||
|
||||
//获取地图
|
||||
tencentMap = tvMapView.getMap();
|
||||
@ -278,6 +281,8 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
|
||||
uiSettings.setRotateGesturesEnabled(false);//禁止地图旋转手势.
|
||||
uiSettings.setTiltGesturesEnabled(false);//禁止倾斜手势.
|
||||
setLocMarkerStyle(LOCATION_TYPE_LOCATION_ROTATE);
|
||||
tencentMap.setLocationSource(new MyTecentLocationSource(this));
|
||||
tencentMap.setMyLocationEnabled(true);
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(dm);
|
||||
FrameLayout.LayoutParams layoutParamsMap = (FrameLayout.LayoutParams) tvMapView.getLayoutParams();//相机的宽高
|
||||
@ -443,6 +448,14 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
imgRoadDirection.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
view.setSelected(!view.isSelected());
|
||||
startMatchEnableDirection = view.isSelected();
|
||||
}
|
||||
});
|
||||
}
|
||||
private long lastClickTime = 0;
|
||||
private int settingHookClickCount = 1;
|
||||
@ -507,9 +520,7 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
|
||||
|
||||
@Override
|
||||
public boolean onDown(float v, float v1) {
|
||||
if (isMapSlide) {
|
||||
setLocMarkerStyle(MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER);
|
||||
}
|
||||
setLocMarkerStyle(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -589,13 +600,13 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
|
||||
|
||||
SharedPreferences spf = getSharedPreferences("MatchEntity", Context.MODE_PRIVATE);
|
||||
Gson gson = new GsonBuilder().serializeSpecialFloatingPointValues().create();
|
||||
String matchedData = spf.getString("data", null);
|
||||
String matchedData = spf.getString("match-data", null);
|
||||
if (matchedData!=null) {
|
||||
List<RoadMatchEntity> dataList = gson.fromJson(matchedData, new TypeToken<List<RoadMatchEntity>>(){}.getType());
|
||||
roadMatchEntityList.addAll(dataList);
|
||||
}
|
||||
// 清空缓存数据
|
||||
spf.edit().remove("data");
|
||||
spf.edit().remove("match-data");
|
||||
spf.edit().commit();
|
||||
}
|
||||
|
||||
@ -632,10 +643,26 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
|
||||
roadMatchEntity.setDataDetail(it);
|
||||
roadMatchEntity.setGeometry((LineString) geometry);
|
||||
// roadMatchEntity.setBuffer(geometry.buffer(MATCH_BUFFER_DISTANCE).toString());
|
||||
// 实时设置当前任务的起始角度
|
||||
if (geometry instanceof LineString) {
|
||||
LineString lineString = (LineString) geometry;
|
||||
// 计算前两个点的坐标角度
|
||||
roadMatchEntity.setAngle(Angle.angle(lineString.getCoordinateN(0), lineString.getCoordinateN(0)));
|
||||
// 获取当前数据的前两个点的方向
|
||||
Coordinate[] coordinates = lineString.getCoordinates();
|
||||
// 循环取出当前数据的坐标点,为防止出现重复点,需要循环做判断
|
||||
Coordinate[] lineCoordinates = new Coordinate[2];
|
||||
lineCoordinates[0] = coordinates[0];
|
||||
lineCoordinates[1] = coordinates[0];
|
||||
for (Coordinate c: coordinates) {
|
||||
if (c.x!=lineCoordinates[0].x&&c.y!=lineCoordinates[0].y) {
|
||||
lineCoordinates[1] = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (lineCoordinates[0]!=lineCoordinates[1]) {
|
||||
double dataBearing = getBearing(lineCoordinates[0].x, lineCoordinates[1].x, lineCoordinates[0].y, lineCoordinates[1].y);
|
||||
roadMatchEntity.setAngle(dataBearing);
|
||||
}
|
||||
roadMatchEntity.setsPoint(lineString.getStartPoint().toString());
|
||||
roadMatchEntity.setePoint(lineString.getEndPoint().toString());
|
||||
}
|
||||
@ -679,24 +706,39 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
|
||||
/**
|
||||
* 开始自动匹配
|
||||
* */
|
||||
private double minDistance = MATCH_START_BUFFER_DISTANCE; // 最小距离,需要在匹配过程点时判断哪个任务是距离最小的
|
||||
private void startMatchRoadLink(Point currentPoint) {
|
||||
if (roadLinkEntityList == null/*没有需要匹配的道路数据*/ || currentPoint == null/*没有位置信息*/) {
|
||||
return;
|
||||
}
|
||||
float currentSpeed = getSpeed();
|
||||
double matchStartDistance = MATCH_BUFFER_DISTANCE;
|
||||
double[] speedAndBearing = getSpeedAndBearing(currentPoint);
|
||||
double currentSpeed = speedAndBearing[0]; // 当前速度
|
||||
double currentBearing = speedAndBearing[1]; // 当前方向
|
||||
double matchMiddleDistance = MATCH_BUFFER_DISTANCE;
|
||||
// 如果速度大于70,则动态调整起点捕捉范围
|
||||
if (currentSpeed>=70) {
|
||||
matchStartDistance = MATCH_BUFFER_DISTANCE*1.5;
|
||||
matchMiddleDistance = MATCH_BUFFER_DISTANCE*1.5;
|
||||
}
|
||||
// 此处开始匹配起点
|
||||
List<RoadMatchEntity> matchStartList = roadLinkEntityList.stream()
|
||||
// 筛选当前任务与起点距离
|
||||
.filter(it-> GeometryTools.createGeometry(it.getsPoint()).distance(currentPoint)<MATCH_START_BUFFER_DISTANCE)
|
||||
// 筛选方向
|
||||
.filter(it-> {
|
||||
if (startMatchEnableDirection) {
|
||||
double dataBearing = it.getAngle();
|
||||
if (currentBearing!=0&&(Math.abs(dataBearing-currentBearing)<=90 || Math.abs(dataBearing-currentBearing)>=270)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
})
|
||||
// 判断筛选出的数据是否已经在匹配列表中,如果不存在,需要自动领取该任务、记录开始采集时间
|
||||
.filter(
|
||||
o -> roadMatchEntityList.stream().noneMatch(roadMatchEntity -> o.getId()==roadMatchEntity.getId()))
|
||||
.collect(Collectors.toList());
|
||||
// 判断筛选出的数据是否已经在匹配列表中,如果不存在,需要自动领取该任务、记录开始采集时间
|
||||
matchStartList = matchStartList.stream().filter(
|
||||
o -> roadMatchEntityList.stream().noneMatch(roadMatchEntity -> o.getId()==roadMatchEntity.getId())
|
||||
).collect(Collectors.toList());
|
||||
if (matchStartList!=null&&!matchStartList.isEmpty()) {
|
||||
// 存在新匹配到的数据
|
||||
matchStartList.stream().forEach(
|
||||
@ -723,37 +765,47 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
|
||||
}
|
||||
|
||||
// 尝试用当前位置点匹配已经匹配到的roadLink,如果能匹配到,需要将该点记录,如果无法匹配,则需要评估已匹配的link是否需要被剔除
|
||||
minDistance = MATCH_START_BUFFER_DISTANCE; // 使用距离起终点的最大阈值初始化最小距离
|
||||
if (!roadMatchEntityList.isEmpty()) {
|
||||
// 因为单个点位只能匹配一条任务,需要获取当前点位距离所有任务最近的距离
|
||||
roadMatchEntityList.stream().forEach(it->it.setCurrentLineDistance(GeometryTools.createGeometry(it.getGeometry()).distance(currentPoint)));
|
||||
// 筛选出本次距离最近的线
|
||||
RoadMatchEntity minRoadMatchEntity = roadMatchEntityList.stream().min((o1, o2)-> {
|
||||
if (o1.getCurrentLineDistance()<o2.getCurrentLineDistance()){
|
||||
return -1;
|
||||
} else if (o1.getCurrentLineDistance()==o2.getCurrentLineDistance()) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
roadMatchEntityList.stream().forEach(it->{
|
||||
double currentDistance = GeometryTools.createGeometry(it.getGeometry()).distance(currentPoint);
|
||||
it.setCurrentLineDistance(currentDistance);
|
||||
if (currentDistance<=minDistance) {
|
||||
minDistance = currentDistance;
|
||||
}
|
||||
}).get();
|
||||
});
|
||||
|
||||
List<RoadMatchEntity> unMatchList = new ArrayList<>();
|
||||
Map<Integer, RoadMatchEntity> finishEntityMap = new HashMap<>();
|
||||
double finalMatchStartDistance = matchStartDistance;
|
||||
double finalMatchMiddleDistance = matchMiddleDistance;
|
||||
roadMatchEntityList.stream().forEach(
|
||||
roadMatchEntity -> {
|
||||
double currentDistance = roadMatchEntity.getCurrentLineDistance();
|
||||
boolean isMatch=currentDistance<= finalMatchStartDistance; // 当前点位是否可以和link匹配到
|
||||
boolean isMatch=currentDistance<= finalMatchMiddleDistance; // 当前点位是否可以和link匹配到
|
||||
if (isMatch) { // 可以匹配到
|
||||
if (minRoadMatchEntity.getId() == roadMatchEntity.getId()) { // 并且该条数据还是最近的点, 将当前点位匹配到此任务下
|
||||
// 可以匹配到,并且是最近的任务,更新任务的开始时间
|
||||
if (roadMatchEntity.getMatchPointList().size() == 0) {
|
||||
if (roadMatchEntity.getCurrentLineDistance()<=minDistance) { // 并且该条数据还是最近的点, 将当前点位匹配到此任务下(注意,当距离完全相等时,同一点位可能同时匹配到多个任务)
|
||||
if (roadMatchEntity.getMatchPointList().size() == 0) { // 可以匹配到,并且从未匹配过,更新任务的开始时间
|
||||
roadMatchEntity.setStartMatchTime(System.currentTimeMillis());
|
||||
}
|
||||
// 更新连续匹配的个数
|
||||
roadMatchEntity.setMatchCount(roadMatchEntity.getMatchCount()+1);
|
||||
roadMatchEntity.setUnMatchCount(0); // 有匹配的数据,则连续未匹配个数归0
|
||||
// 匹配到最近的任务,将当前点加入到已匹配道路中
|
||||
roadMatchEntity.getMatchPointList().add(new MyCoordinate(currentPoint.getX(), currentPoint.getY()));
|
||||
// 如果连续匹配个数大于1(可以连成线),更新已匹配长度
|
||||
if (roadMatchEntity.getMatchCount()>1) {
|
||||
roadMatchEntity.setMatchedLength(
|
||||
roadMatchEntity.getMatchedLength()
|
||||
+
|
||||
// 加上最后两个点的长度
|
||||
GeometryTools.getLineStringByMyCoordinate(roadMatchEntity.getMatchPointList().subList(roadMatchEntity.getMatchPointList().size()-2, roadMatchEntity.getMatchPointList().size())).getLength()
|
||||
);
|
||||
}
|
||||
} else { // 在阈值内,但是并非最近的点
|
||||
roadMatchEntity.setMatchCount(0); // 连续匹配个数置为0
|
||||
}
|
||||
roadMatchEntity.setUnMatchCount(0); // 有匹配的数据,则连续未匹配个数归0(即使不是最近的数据,在阈值内即认为可匹配,未匹配点数也置为0)
|
||||
|
||||
double currentEndDistance = currentPoint.distance(GeometryTools.createGeometry(roadMatchEntity.getePoint())); // 当前距离终点的距离
|
||||
// 记录本次的匹配距离,如果本次匹配距离大于上一次,且上一次匹配终点时间不为0(说明已经提前匹配到终点了),则结束匹配,否则继续等待匹配,设置过EndMathchTime的数据即为可以结束匹配的数据,下一次如果未匹配,也可以结束
|
||||
if (roadMatchEntity.getEndMathchTime()>0/*endMatchTime不为0,说明该数据已经匹配到终点*/&¤tEndDistance>roadMatchEntity.getLastEndDistance()) {
|
||||
@ -761,17 +813,17 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
|
||||
// 更新终点时间为距离终点逐渐变大时的时间
|
||||
roadMatchEntity.setEndMathchTime(System.currentTimeMillis());
|
||||
}
|
||||
// 匹配到终点、或匹配距离超过90%
|
||||
if ((roadMatchEntity.getMatchPointList().size()>=2&&GeometryTools.getLineStringByMyCoordinate(roadMatchEntity.getMatchPointList()).getLength()/roadMatchEntity.getLength()>=MATCH_CONFIRM_FINISH_BUFFER)
|
||||
|| currentEndDistance<= finalMatchStartDistance) {
|
||||
// 匹配距离超过指定阈值,认为该条数据可完成,记录当前位置与终点的距离,当距离从小变大时,完成该任务
|
||||
if (roadMatchEntity.getMatchPointList().size()>=2&&roadMatchEntity.getMatchedLength()/roadMatchEntity.getLength()>=MATCH_CONFIRM_FINISH_BUFFER) {
|
||||
roadMatchEntity.setEndMathchTime(System.currentTimeMillis());
|
||||
// 匹配到终点后,记录该条数据的最新一次匹配距离,当下一次匹配距离大于当前距离,则认为该数据完全匹配,结束匹配
|
||||
roadMatchEntity.setLastEndDistance(currentEndDistance);
|
||||
}
|
||||
//=============如果在匹配范围内,但是该数据并非最近的点,不需要记录匹配,也无需增加未匹配点的个数
|
||||
} else { // 无法匹配
|
||||
// 将无法匹配的点位个数记录到对象中
|
||||
// 更新连续无法匹配的点位个数
|
||||
roadMatchEntity.setUnMatchCount(roadMatchEntity.getUnMatchCount()+1);
|
||||
// 有未匹配的数据,连续匹配个数也归0
|
||||
roadMatchEntity.setMatchCount(0);// 设置连续匹配的数据个数为0
|
||||
roadMatchEntity.getUnMatchPointList().add(new MyCoordinate(currentPoint.getX(), currentPoint.getY()));
|
||||
// 当连续未匹配个数大于等于20个时,该任务被认为可以结束(舍弃或完成-需根据匹配到的数据长度与任务长度做对比)
|
||||
@ -780,7 +832,7 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
|
||||
if (matchPointList == null || matchPointList.size()<2) { // 已匹配的点位不足2个,无法计算长度,直接放弃该任务
|
||||
unMatchList.add(roadMatchEntity);
|
||||
} else {
|
||||
if (GeometryTools.getLineStringByMyCoordinate(matchPointList).getLength()/roadMatchEntity.getLength()>=MATCH_CONFIRM_FINISH_BUFFER) { // 已匹配距离与任务长度距离比例超过指定阈值,该任务可完成
|
||||
if (roadMatchEntity.getMatchedLength()/roadMatchEntity.getLength()>=MATCH_CONFIRM_FINISH_BUFFER) { // 已匹配距离与任务长度距离比例超过指定阈值,该任务可完成
|
||||
roadMatchEntity.setEndMathchTime(System.currentTimeMillis());
|
||||
finishEntityMap.put(roadMatchEntity.getId(), roadMatchEntity);
|
||||
} else {
|
||||
@ -788,35 +840,6 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
|
||||
}
|
||||
}
|
||||
}
|
||||
// // 该数据未匹配,但是如果此前已经匹配到结束点,则仍然认为匹配成功
|
||||
// if (roadMatchEntity.getEndMathchTime()>0) {
|
||||
// finishEntityMap.put(roadMatchEntity.getId(), roadMatchEntity);
|
||||
// } else {
|
||||
// // 判断当前是否存在已匹配的点
|
||||
// if (roadMatchEntity.getMatchPointList().size()>1) { // 存在匹配的点超过1个,根据长度判断
|
||||
// if (GeometryTools.getLineStringByMyCoordinate(roadMatchEntity.getMatchPointList()).getLength()/roadMatchEntity.getLength()>UNMATCH_GIVE_UP_DISTANCE_BUFFER) {
|
||||
// // 匹配距离超过20%,根据匹配点和未匹配点个数的对比率判断是否需要放弃
|
||||
// if (((float)roadMatchEntity.getUnMatchPointList().size())/roadMatchEntity.getMatchPointList().size()>UNMATCH_COUNT_BUFFER) {
|
||||
// unMatchList.add(roadMatchEntity);
|
||||
// }
|
||||
// } else {// 当前匹配距离不超过20%,则必须有连续多个点未匹配才可以放弃该Link
|
||||
// if (roadMatchEntity.getUnMatchCount()>UNMATCH_BUFFER_MIDDLE_BUFFER) {
|
||||
// unMatchList.add(roadMatchEntity);
|
||||
// }
|
||||
// }
|
||||
// } else { // 从未匹配过的数据
|
||||
// // 未匹配个数超过指定阈值,也认为数据不匹配
|
||||
// if (roadMatchEntity.getMatchPointList().size()==0) { // 已匹配的个数为0
|
||||
// if (roadMatchEntity.getUnMatchCount()>UNMATCH_BUFFER_START_BUFFER) {
|
||||
// unMatchList.add(roadMatchEntity);
|
||||
// }
|
||||
// } else if (roadMatchEntity.getMatchPointList().size()==1) { // 已匹配的个数为1
|
||||
// if (roadMatchEntity.getUnMatchCount()>UNMATCH_BUFFER_MIDDLE_BUFFER) {
|
||||
// unMatchList.add(roadMatchEntity);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
);
|
||||
@ -838,22 +861,27 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
|
||||
}
|
||||
|
||||
if (!unMatchList.isEmpty()) {
|
||||
// 过滤需要舍弃的link
|
||||
for (RoadMatchEntity unMatchEntity: unMatchList) {
|
||||
roadMatchEntityList.remove(unMatchEntity);
|
||||
}
|
||||
cancelReciverTask(unMatchList).subscribe(new Consumer<PoiEntity>() {
|
||||
cancelReciverTask(unMatchList).subscribe(new Observer<PoiEntity>() {
|
||||
@Override
|
||||
public void accept(PoiEntity poiEntity) throws Exception {
|
||||
public void onSubscribe(Disposable d) {
|
||||
// 过滤需要舍弃的link
|
||||
for (RoadMatchEntity unMatchEntity: unMatchList) {
|
||||
roadMatchEntityList.remove(unMatchEntity);
|
||||
}
|
||||
}
|
||||
}, new Consumer<Throwable>() {
|
||||
|
||||
@Override
|
||||
public void accept(Throwable throwable) throws Exception {
|
||||
Toast.makeText(AutoTakePictureActivity.this, throwable.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
public void onNext(PoiEntity poiEntity) {
|
||||
|
||||
}
|
||||
}, new Action() {
|
||||
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
public void onError(Throwable e) {
|
||||
Toast.makeText(AutoTakePictureActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
// 重新刷新地图
|
||||
initRoadLine2Map();
|
||||
}
|
||||
@ -1102,7 +1130,9 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
|
||||
.token(Constant.ACCESS_TOKEN);
|
||||
Response response = okGoBuilder.getSynchronization();
|
||||
Gson gson = new Gson();
|
||||
TaskByNetBean taskByNetBean = gson.fromJson(response.body().string(), TaskByNetBean.class);
|
||||
String body = response.body().string();
|
||||
TaskByNetBean taskByNetBean = gson.fromJson(body, TaskByNetBean.class);
|
||||
Log.d("AutoTake:", body);
|
||||
if (taskByNetBean.getCode() == 200) {
|
||||
// 继续保存
|
||||
TaskByNetBean.BodyBean listBean = taskByNetBean.getBody();
|
||||
@ -1382,12 +1412,12 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
|
||||
case R.id.iv_zoom_add://放大
|
||||
CameraUpdate cameraUpdateIn = CameraUpdateFactory.zoomIn();
|
||||
tencentMap.animateCamera(cameraUpdateIn);
|
||||
setLocMarkerStyle(MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER);
|
||||
setLocMarkerStyle(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER);
|
||||
break;
|
||||
case R.id.iv_zoom_del://缩小
|
||||
CameraUpdate cameraUpdateOut = CameraUpdateFactory.zoomOut();
|
||||
tencentMap.animateCamera(cameraUpdateOut);
|
||||
setLocMarkerStyle(MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER);
|
||||
setLocMarkerStyle(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER);
|
||||
break;
|
||||
case R.id.iv_location://定位:
|
||||
if (Constant.currentLocation != null) {
|
||||
@ -1420,8 +1450,6 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
|
||||
|
||||
/*设置定位图标样式*/
|
||||
private void setLocMarkerStyle(int type) {
|
||||
tencentMap.setLocationSource(new MyTecentLocationSource(this));
|
||||
tencentMap.setMyLocationEnabled(true);
|
||||
MyLocationStyle locationStyle = new MyLocationStyle();
|
||||
//LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER
|
||||
locationStyle = locationStyle.myLocationType(type);
|
||||
@ -1432,7 +1460,7 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
|
||||
locationStyle.fillColor(getResources().getColor(android.R.color.transparent));
|
||||
locationStyle.strokeWidth(1);
|
||||
tencentMap.setMyLocationStyle(locationStyle);
|
||||
if (LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER == type) {
|
||||
if (LOCATION_TYPE_LOCATION_ROTATE == type) {
|
||||
ivLocation.setEnabled(false);
|
||||
} else {
|
||||
ivLocation.setEnabled(true);
|
||||
@ -1592,7 +1620,7 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
|
||||
// roadMatchEntity已匹配数据如果存在,缓存
|
||||
SharedPreferences.Editor editor = getSharedPreferences("MatchEntity", Context.MODE_PRIVATE).edit();
|
||||
Gson gson = new GsonBuilder().serializeSpecialFloatingPointValues().create();
|
||||
editor.putString("data", gson.toJson(roadMatchEntityList));
|
||||
editor.putString("match-data", gson.toJson(roadMatchEntityList));
|
||||
editor.commit();
|
||||
}
|
||||
if (gpsUtils!=null) {
|
||||
@ -1956,7 +1984,7 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
|
||||
}
|
||||
// 判断当前点位和上一个点位的距离,如果距离过近,忽略该点
|
||||
Point currentPoint = (Point) GeometryTools.createGeometry(new LatLng(tencentLocation.getLatitude(), tencentLocation.getLongitude()));
|
||||
if (lastPositionPoint!=null&&lastPositionPoint.distance(currentPoint)<MATCH_BUFFER_DISTANCE) { // 如果当前点小于最小距离阈值,过滤该数据
|
||||
if (lastPositionPoint!=null&&lastPositionPoint.distance(currentPoint)<3e-7) { // 如果当前点小于最小距离阈值,过滤该数据
|
||||
return false;
|
||||
}
|
||||
lastPositionPoint = currentPoint;
|
||||
@ -1993,15 +2021,21 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
|
||||
}
|
||||
});
|
||||
|
||||
private float getSpeedAndBearing() {
|
||||
float bearing = 0;
|
||||
if (Constant.currentLocation.getDirection() != 0) {
|
||||
bearing = (float) Constant.currentLocation.getDirection();
|
||||
} else {
|
||||
// 使用上一个点和当前点位的向量计算方向
|
||||
if (oldCurrentLocation!=null&&oldCurrentLocation.getLatitude()!=Constant.currentLocation.getLatitude()&&oldCurrentLocation.getLongitude()!=Constant.currentLocation.getLongitude()) {
|
||||
private double[] getSpeedAndBearing(Point currentPoint) {
|
||||
double[] speedAndBearing = new double[2];
|
||||
|
||||
}
|
||||
double bearing = 0;
|
||||
// if (Constant.currentLocation.getDirection() != 0) {
|
||||
// bearing = (float) Constant.currentLocation.getDirection();
|
||||
// } else {
|
||||
// // 使用上一个点和当前点位的向量计算方向
|
||||
// if (oldCurrentLocation!=null&&oldCurrentLocation.getLatitude()!=Constant.currentLocation.getLatitude()&&oldCurrentLocation.getLongitude()!=Constant.currentLocation.getLongitude()) {
|
||||
// bearing = getBearing(oldCurrentLocation.getLongitude(), Constant.currentLocation.getLongitude(), oldCurrentLocation.getLatitude(), Constant.currentLocation.getLatitude());
|
||||
// }
|
||||
// }
|
||||
// 使用上一个点和当前点位的向量计算方向
|
||||
if (oldCurrentLocation!=null&&oldCurrentLocation.getX()!=currentPoint.getX()&&oldCurrentLocation.getY()!=currentPoint.getY()) {
|
||||
bearing = getBearing(oldCurrentLocation.getX(), currentPoint.getX(), oldCurrentLocation.getY(), currentPoint.getY());
|
||||
}
|
||||
|
||||
float speed = Constant.currentLocation.getSpeed();//米/秒
|
||||
@ -2009,14 +2043,28 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
|
||||
speed = (speed * 3600 / 1000);//km/h
|
||||
} else {
|
||||
if (oldCurrentLocation != null) {
|
||||
LatLng startLatLng = new LatLng(oldCurrentLocation.getLatitude(), oldCurrentLocation.getLongitude());//旧的坐标
|
||||
LatLng endLatLng = new LatLng(Constant.currentLocation.getLatitude(), Constant.currentLocation.getLongitude());//新的坐标
|
||||
LatLng startLatLng = new LatLng(oldCurrentLocation.getY(), oldCurrentLocation.getX());//旧的坐标
|
||||
LatLng endLatLng = new LatLng(currentPoint.getY(), currentPoint.getX());//新的坐标
|
||||
double geometry = GeometryTools.distanceToDouble(startLatLng, endLatLng);//米
|
||||
speed = (float) (geometry * 3600 / 1000);
|
||||
}
|
||||
oldCurrentLocation = Constant.currentLocation;
|
||||
oldCurrentLocation = currentPoint;
|
||||
}
|
||||
return speed;
|
||||
speedAndBearing[0] = speed;
|
||||
speedAndBearing[1] = bearing;
|
||||
|
||||
return speedAndBearing;
|
||||
}
|
||||
|
||||
private double getBearing(double startLongitude, double endLongitude, double startLatitude, double endLatitude) {
|
||||
double x = endLongitude - startLongitude;
|
||||
double y = endLatitude - startLatitude;
|
||||
double angle = Math.atan(x / y)*180/Math.PI;
|
||||
if((x>0&&y<0)||(x<0&&y<0)){
|
||||
angle=angle+180;
|
||||
}
|
||||
angle = (angle+720)%360;
|
||||
return angle;
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
@ -2026,17 +2074,17 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
|
||||
return;
|
||||
}
|
||||
TencentLocation tencentLocation = (TencentLocation) msg.obj;
|
||||
if (tencentMap != null && ivLocation!=null && !ivLocation.isEnabled()) { // 当定位按钮禁用,
|
||||
CameraUpdate cameraSigma = CameraUpdateFactory.newCameraPosition(new CameraPosition(
|
||||
new LatLng(tencentLocation.getLatitude(), tencentLocation.getLongitude()), //中心点坐标,地图目标经纬度
|
||||
17, //目标缩放级别
|
||||
0, //目标倾斜角
|
||||
0)); //目标旋转角 0~360° (正北方为0)
|
||||
tencentMap.animateCamera(cameraSigma);
|
||||
}
|
||||
// if (tencentMap != null && ivLocation!=null && !ivLocation.isEnabled()) { // 当定位按钮禁用,
|
||||
// CameraUpdate cameraSigma = CameraUpdateFactory.newCameraPosition(new CameraPosition(
|
||||
// new LatLng(tencentLocation.getLatitude(), tencentLocation.getLongitude()), //中心点坐标,地图目标经纬度
|
||||
// 17, //目标缩放级别
|
||||
// 0, //目标倾斜角
|
||||
// 0)); //目标旋转角 0~360° (正北方为0)
|
||||
// tencentMap.animateCamera(cameraSigma);
|
||||
// }
|
||||
// 判断当前点位和上一个点位的距离,如果距离过近,忽略该点
|
||||
Point currentPoint = (Point) GeometryTools.createGeometry(new LatLng(tencentLocation.getLatitude(), tencentLocation.getLongitude()));
|
||||
if (lastPositionPoint!=null&&lastPositionPoint.distance(currentPoint)<MATCH_BUFFER_DISTANCE) { // 如果当前点小于最小距离阈值,过滤该数据
|
||||
if (lastPositionPoint!=null&&lastPositionPoint.distance(currentPoint)<5e-7) { // 如果当前点小于最小距离阈值,过滤该数据
|
||||
return;
|
||||
}
|
||||
lastPositionPoint = currentPoint;
|
||||
|
@ -36,6 +36,7 @@ public class RoadMatchEntity implements Serializable {
|
||||
private int unMatchCount; // <连续>未匹配到的点位个数
|
||||
private List<MyCoordinate> matchPointList = new ArrayList<>(); // 已匹配的点位列表
|
||||
private List<MyCoordinate> unMatchPointList = new ArrayList<>(); // 未匹配的点位列表
|
||||
private double matchedLength = 0;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
@ -162,6 +163,14 @@ public class RoadMatchEntity implements Serializable {
|
||||
this.currentLineDistance = currentLineDistance;
|
||||
}
|
||||
|
||||
public double getMatchedLength() {
|
||||
return matchedLength;
|
||||
}
|
||||
|
||||
public void setMatchedLength(double matchedLength) {
|
||||
this.matchedLength = matchedLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
@ -103,6 +103,7 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList
|
||||
private RadioButton rbtnRoadOpen/*道路已开通*/, rbtnRoadPartOpen/*道路部分开通*/, rbtnRoadHasntOpen/*道路未开通*/, rbtnRoadHasntFind/*道路未找到*/, rbtnRoadOther/*其他*/;
|
||||
private RadioGroup rgRoadStatus; // 道路状态的radioGroup
|
||||
private EditText edtCheckedOther;
|
||||
private int existence = 0; // 是否存在
|
||||
|
||||
public static RoadFragment newInstance(Bundle bundle) {
|
||||
RoadFragment fragment = new RoadFragment();
|
||||
@ -230,6 +231,10 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList
|
||||
@Override
|
||||
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
||||
rgRoadStatus.setTag(findViewById(checkedId).getTag());
|
||||
existence = (int) findViewById(checkedId).getTag();
|
||||
if (showPoiEntity!=null) {
|
||||
showPoiEntity.setExistence(existence);
|
||||
}
|
||||
switch (checkedId) {
|
||||
case R.id.rbtn_road_other:
|
||||
edtCheckedOther.setVisibility(View.VISIBLE);
|
||||
@ -400,6 +405,15 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList
|
||||
if (showPoiEntity.getTaskId()>0) {
|
||||
etRoadName.setEnabled(false);
|
||||
}
|
||||
if (rgRoadStatus!=null) {
|
||||
for (int i = 0; i < rgRoadStatus.getChildCount(); i++) {
|
||||
RadioButton childAt = (RadioButton) rgRoadStatus.getChildAt(i);
|
||||
if (childAt.getTag().equals(showPoiEntity.getExistence())) {
|
||||
childAt.setChecked(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -648,7 +662,7 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList
|
||||
httpParams.put("workType", 0);
|
||||
httpParams.put("memo", poiEntity.getMemo());
|
||||
// 增加对应九天平台的参数
|
||||
httpParams.put("existence", rgRoadStatus.getTag().toString());
|
||||
httpParams.put("existence", existence);
|
||||
httpParams.put("description", edtCheckedOther!=null&&edtCheckedOther.isShown()? edtCheckedOther.getText().toString().trim(): "");
|
||||
|
||||
OkGoBuilder okGoBuilder = OkGoBuilder.getInstance()
|
||||
@ -719,7 +733,7 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList
|
||||
httpParams.put("workType", 0);
|
||||
httpParams.put("memo", poiEntity.getMemo());
|
||||
// 增加对应九天平台的参数
|
||||
httpParams.put("existence", rgRoadStatus.getTag().toString());
|
||||
httpParams.put("existence", existence);
|
||||
httpParams.put("description", edtCheckedOther!=null&&edtCheckedOther.isShown()? edtCheckedOther.getText().toString().trim(): "");
|
||||
OkGoBuilder okGoBuilder = OkGoBuilder.getInstance()
|
||||
.time(30)
|
||||
|
@ -3,8 +3,8 @@ package com.navinfo.outdoor.http;
|
||||
public class HttpInterface {
|
||||
// public static final String IP = "http://172.23.138.133:9999/m4";//测试接口-IP
|
||||
public static final String IPm = "http://dtxbmaps.navinfo.com/dtxb/dev/m4";//开发接口-外网
|
||||
public static final String IP = "http://dtxbmaps.navinfo.com/dtxb/test/m4";//测试接口-外网
|
||||
public static final String IP1 = "http://dtxbmaps.navinfo.com/dtxb/m4";//正式接口
|
||||
public static final String IP1 = "http://dtxbmaps.navinfo.com/dtxb/test/m4";//测试接口-外网
|
||||
public static final String IP = "http://dtxbmaps.navinfo.com/dtxb/m4";//正式接口
|
||||
public static final String USER_PATH = "/user/";//我的
|
||||
public static final String MSG_LIST_PATH = "/msgList/";//发现
|
||||
public static final String USER_LOGIN_PATH = "/userlogin/";//登录
|
||||
|
14
app/src/main/res/drawable/selector_direction.xml
Normal file
14
app/src/main/res/drawable/selector_direction.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="true"
|
||||
android:drawable="@mipmap/direction_press"/> <!-- pressed -->
|
||||
<item android:state_focused="true"
|
||||
android:drawable="@mipmap/direction_press"/> <!-- focused -->
|
||||
<item android:state_selected="true"
|
||||
android:drawable="@mipmap/direction_press"/>
|
||||
<item android:state_checked="true"
|
||||
android:drawable="@mipmap/direction_press"/>
|
||||
<item android:state_enabled="false"
|
||||
android:drawable="@mipmap/direction_press"/>
|
||||
<item android:drawable="@mipmap/direction" /> <!-- default -->
|
||||
</selector>
|
14
app/src/main/res/drawable/selector_picture_map_change.xml
Normal file
14
app/src/main/res/drawable/selector_picture_map_change.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="true"
|
||||
android:drawable="@mipmap/exchange_press"/> <!-- pressed -->
|
||||
<item android:state_focused="true"
|
||||
android:drawable="@mipmap/exchange_press"/> <!-- focused -->
|
||||
<item android:state_selected="true"
|
||||
android:drawable="@mipmap/exchange_press"/>
|
||||
<item android:state_checked="true"
|
||||
android:drawable="@mipmap/exchange_press"/>
|
||||
<item android:state_enabled="false"
|
||||
android:drawable="@mipmap/exchange_press"/>
|
||||
<item android:drawable="@mipmap/exchange" /> <!-- default -->
|
||||
</selector>
|
@ -127,12 +127,13 @@
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/btn_switch"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:background="@drawable/selector_round_bg"
|
||||
android:layout_marginTop="25dp"
|
||||
android:layout_marginEnd="25dp"
|
||||
android:src="@mipmap/switcher"
|
||||
android:src="@drawable/selector_picture_map_change"
|
||||
android:padding="@dimen/default_widget_padding"
|
||||
android:layout_marginRight="@dimen/default_widget_padding"
|
||||
android:text="切换"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
@ -160,16 +161,29 @@
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/img_navi_distance"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:src="@drawable/selector_navi_distance"
|
||||
android:background="@drawable/selector_round_bg"
|
||||
android:text="按距离自动导航"
|
||||
android:padding="8dp"
|
||||
android:visibility="gone"
|
||||
android:padding="@dimen/default_widget_padding"
|
||||
android:layout_margin="@dimen/default_widget_padding"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/location_switch"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/img_road_direction"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:background="@drawable/selector_round_bg"
|
||||
android:text="起点方向捕捉"
|
||||
android:src="@drawable/selector_direction"
|
||||
android:padding="@dimen/default_widget_padding"
|
||||
android:layout_margin="@dimen/default_widget_padding"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/img_navi_distance"></ImageView>
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/radio_group_picture"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -23,6 +23,7 @@
|
||||
android:textSize="@dimen/pickerview_topbar_title_textsize"
|
||||
android:textColor="@color/colorWhite"
|
||||
android:padding="@dimen/default_widget_padding"
|
||||
android:visibility="gone"
|
||||
android:background="@drawable/selector_red_bg"
|
||||
app:layout_constraintRight_toLeftOf="@id/btn_delete"
|
||||
app:layout_constraintBaseline_toBaselineOf="@id/btn_delete"
|
||||
|
@ -117,6 +117,7 @@
|
||||
android:id="@+id/img_navi_distance"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:visibility="gone"
|
||||
android:src="@drawable/selector_navi_distance"
|
||||
android:background="@drawable/selector_round_bg"
|
||||
android:text="按距离自动导航"
|
||||
|
BIN
app/src/main/res/mipmap-xxhdpi/direction.png
Normal file
BIN
app/src/main/res/mipmap-xxhdpi/direction.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/direction_press.png
Normal file
BIN
app/src/main/res/mipmap-xxhdpi/direction_press.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/exchange.png
Normal file
BIN
app/src/main/res/mipmap-xxhdpi/exchange.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/exchange_press.png
Normal file
BIN
app/src/main/res/mipmap-xxhdpi/exchange_press.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
Loading…
x
Reference in New Issue
Block a user