opt road match
This commit is contained in:
@@ -68,13 +68,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import static java.lang.Math.PI;
|
||||
|
||||
public class AMapViewWrapper implements IMogoMapView,
|
||||
IMogoMapUIController,
|
||||
LocationListener,
|
||||
@@ -1045,71 +1042,83 @@ public class AMapViewWrapper implements IMogoMapView,
|
||||
return matchRoad(id, lon, lat, angle, isGpsLocation, isRTK, true);
|
||||
}
|
||||
|
||||
int[] colors = new int[]{Color.RED, Color.GREEN, Color.BLUE};
|
||||
int colorIndex = 0;
|
||||
private double[] matchRoad(String id, double lon, double lat, double angle, boolean isGpsLocation, boolean isRTK, boolean usdCache) {
|
||||
double wgs[] = new double[]{lon, lat};
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
//
|
||||
// try {
|
||||
// PolylineOptions options = new PolylineOptions( );
|
||||
// options.setColor( Color.WHITE );
|
||||
// options.setId( "test-line"+new Random( ).nextLong() );
|
||||
// options.setGps( true );
|
||||
// options.setLineWidth( 3 );
|
||||
// List<LonLatPoint> points = singlePointRoadInfo.getCoords();
|
||||
// ArrayList< LonLat > lonLats = new ArrayList<>( );
|
||||
// for ( LonLatPoint point : points ) {
|
||||
// lonLats.add( new LonLat( point.getLongitude(), point.getLatitude() ) );
|
||||
// }
|
||||
// options.setLonLats( lonLats );
|
||||
// mMapView.getMapAutoViewHelper().drawThickLine( options );
|
||||
// } catch( Exception e ){
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
SinglePointRoadInfo singlePointRoadInfo = MapDataApi.INSTANCE.getSinglePointMatchRoad(((float) wgs[0]), ((float) wgs[1]), ((float) angle), isGpsLocation, isRTK);
|
||||
if ( singlePointRoadInfo == null || singlePointRoadInfo.getCoords() == null || singlePointRoadInfo.getCoords().isEmpty() ) {
|
||||
return null;
|
||||
}
|
||||
double matchedPoint[] = PointInterpolatorUtil.mergeToRoad(wgs[0], wgs[1], singlePointRoadInfo.getCoords());
|
||||
return matchedPoint;
|
||||
|
||||
// RoadCacheWrapper roadCache = roadCacheMap.get(id);
|
||||
// if (roadCache == null) {
|
||||
// SinglePointRoadInfo singlePointRoadInfo = MapDataApi.INSTANCE.getSinglePointMatchRoad(((float) wgs[0]), ((float) wgs[1]), ((float) angle), isGpsLocation, isRTK);
|
||||
// if (singlePointRoadInfo != null && singlePointRoadInfo.getCoords() != null && !singlePointRoadInfo.getCoords().isEmpty()) {
|
||||
// Log.i("timer-matchRoad-4", "cost " + (System.currentTimeMillis() - start) + "ms roadId: " + singlePointRoadInfo.getRoadId());
|
||||
// roadCache = new RoadCacheWrapper(singlePointRoadInfo.getCoords());
|
||||
// }
|
||||
// SinglePointRoadInfo singlePointRoadInfo = MapDataApi.INSTANCE.getSinglePointMatchRoad(((float) wgs[0]), ((float) wgs[1]), ((float) angle), isGpsLocation, isRTK);
|
||||
// if ( singlePointRoadInfo == null || singlePointRoadInfo.getCoords() == null || singlePointRoadInfo.getCoords().isEmpty() ) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// Log.i("timer-matchRoad-1", "cost " + (System.currentTimeMillis() - start) + "ms");
|
||||
// if (roadCache != null
|
||||
// && roadCache.getRoad() != null
|
||||
// && !roadCache.getRoad().isEmpty()) {
|
||||
// start = System.currentTimeMillis();
|
||||
// double matchedPoint[] = PointInterpolatorUtil.mergeToRoad(wgs[0], wgs[1], roadCache.getRoad());
|
||||
// if (matchedPoint[2] > 0 && matchedPoint[2] < 1.5) {
|
||||
//// if (roadCache.inCache(matchedPoint[0], matchedPoint[1])) {
|
||||
// roadCacheMap.put(id, roadCache);
|
||||
// Log.i("timer-matchRoad-3", "cost " + (System.currentTimeMillis() - start) + "ms");
|
||||
// return matchedPoint;
|
||||
//// }
|
||||
//// roadCacheMap.put(id, null);
|
||||
//// Log.i("timer-matchRoad-2", "cost " + (System.currentTimeMillis() - start) + "ms roadId: "+roadCache.getLastLat());
|
||||
//// return matchRoad(id, lon, lat, angle, isGpsLocation, isRTK,false);
|
||||
// }else{
|
||||
// double matchedPoint[] = PointInterpolatorUtil.mergeToRoad(wgs[0], wgs[1], singlePointRoadInfo.getCoords());
|
||||
// return matchedPoint;
|
||||
|
||||
RoadCacheWrapper roadCache = roadCacheMap.get(id);
|
||||
double matchThreshold = -1;
|
||||
if (roadCache == null) {
|
||||
SinglePointRoadInfo singlePointRoadInfo = MapDataApi.INSTANCE.getSinglePointMatchRoad(((float) wgs[0]), ((float) wgs[1]), ((float) angle), isGpsLocation, isRTK);
|
||||
if (singlePointRoadInfo != null && singlePointRoadInfo.getCoords() != null && !singlePointRoadInfo.getCoords().isEmpty()) {
|
||||
Log.i("timer-matchRoad-4", "cost " + (System.currentTimeMillis() - start) + "ms roadId: " + singlePointRoadInfo.getRoadId());
|
||||
roadCache = new RoadCacheWrapper(singlePointRoadInfo.getCoords());
|
||||
roadCache.setLaneWidth(singlePointRoadInfo.getLaneWidth());
|
||||
// try {
|
||||
// PolylineOptions options = new PolylineOptions( );
|
||||
// options.setColor( colors[colorIndex++] );
|
||||
// options.setId( "test-line"+new Random( ).nextLong() );
|
||||
// options.setGps( true );
|
||||
// options.setLineWidth( 3 );
|
||||
// List<LonLatPoint> points = singlePointRoadInfo.getCoords();
|
||||
// ArrayList< LonLat > lonLats = new ArrayList<>( );
|
||||
// for ( LonLatPoint point : points ) {
|
||||
// lonLats.add( new LonLat( point.getLongitude(), point.getLatitude() ) );
|
||||
// }
|
||||
// options.setLonLats( lonLats );
|
||||
// mMapView.getMapAutoViewHelper().drawThickLine( options );
|
||||
// if (colorIndex >= colors.length) {
|
||||
// colorIndex = 0;
|
||||
// }
|
||||
// } catch( Exception e ){
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
Log.i("timer-matchRoad-1", "cost " + (System.currentTimeMillis() - start) + "ms");
|
||||
if (roadCache != null
|
||||
&& roadCache.getRoad() != null
|
||||
&& !roadCache.getRoad().isEmpty()) {
|
||||
start = System.currentTimeMillis();
|
||||
matchThreshold = roadCache.getLaneWidth() / 4;
|
||||
|
||||
double matchedPoint[] = PointInterpolatorUtil.mergeToRoad(wgs[0], wgs[1], roadCache.getRoad());
|
||||
if (matchThreshold>0&&matchedPoint[2] > 0 && matchedPoint[2] <= matchThreshold) {
|
||||
// if (roadCache.inCache(matchedPoint[0], matchedPoint[1])) {
|
||||
roadCacheMap.put(id, roadCache);
|
||||
Log.i("timer-matchRoad-3", "cost " + (System.currentTimeMillis() - start) + "ms");
|
||||
return matchedPoint;
|
||||
// }
|
||||
// roadCacheMap.put(id, null);
|
||||
// Log.i("timer-matchRoad-2", "cost " + (System.currentTimeMillis() - start) + "ms roadId: " + roadCache.getLastLat());
|
||||
//// if(usdCache) {
|
||||
//// return matchRoad(id, lon, lat, angle, isGpsLocation, isRTK, false);
|
||||
//// }else{
|
||||
//// return null;
|
||||
//// }
|
||||
// Log.i("timer-matchRoad-2", "cost " + (System.currentTimeMillis() - start) + "ms roadId: "+roadCache.getLastLat());
|
||||
// return matchRoad(id, lon, lat, angle, isGpsLocation, isRTK,false);
|
||||
} else if (matchedPoint[2] > matchThreshold && matchedPoint[2] < 1.5) {
|
||||
return null;
|
||||
} else {
|
||||
roadCacheMap.put(id, null);
|
||||
Log.i("timer-matchRoad-2", "cost " + (System.currentTimeMillis() - start) + "ms roadId: " + roadCache.getLastLat());
|
||||
if (usdCache) {
|
||||
return matchRoad(id, lon, lat, angle, isGpsLocation, isRTK, false);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
// roadCacheMap.put(id, null);
|
||||
// return null;
|
||||
}
|
||||
}
|
||||
roadCacheMap.put(id, null);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,6 +14,8 @@ public class RoadCacheWrapper {
|
||||
private double lastDistanceDiff;
|
||||
private int roadLength = -1;
|
||||
|
||||
private float laneWidth = -1;
|
||||
|
||||
public RoadCacheWrapper(List<LonLatPoint> road) {
|
||||
setRoad(road);
|
||||
}
|
||||
@@ -51,6 +53,14 @@ public class RoadCacheWrapper {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public float getLaneWidth() {
|
||||
return laneWidth;
|
||||
}
|
||||
|
||||
public void setLaneWidth(float laneWidth) {
|
||||
this.laneWidth = laneWidth;
|
||||
}
|
||||
|
||||
public boolean inCache(double lon, double lat) {
|
||||
if (roadLength > 0) {
|
||||
LonLatPoint start = road.get(0);
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.mogo.map.impl.custom.utils;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.mogo.cloud.commons.utils.CoordinateUtils;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.zhidaoauto.map.sdk.open.query.LonLatPoint;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -134,18 +137,25 @@ public class PointInterpolatorUtil {
|
||||
if (cross < 0) {
|
||||
// 垂足没有在线段内,所以也无需计算最短距离
|
||||
// result[2] = Math.sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
|
||||
// Log.d("getFootAndMinDistance", "垂足不在线段内--1");
|
||||
return result;
|
||||
}
|
||||
double d2 = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
|
||||
if (cross > d2) {
|
||||
// 垂足没有在线段内,所以也无需计算最短距离
|
||||
// result[2] = Math.sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2));
|
||||
// Log.d("getFootAndMinDistance", "垂足不在线段内--2");
|
||||
return result;
|
||||
}
|
||||
double r = cross / d2;
|
||||
result[0] = x1 + (x2 - x1) * r;
|
||||
result[1] = y1 + (y2 - y1) * r;
|
||||
result[2] = Math.sqrt((x - result[0]) * (x - result[0]) + (result[1] - y) * (result[1] - y));
|
||||
// NumberFormat numberFormat = NumberFormat.getInstance();
|
||||
// numberFormat.setMaximumFractionDigits(4);
|
||||
// String formatNum = numberFormat.format(Math.sqrt((x - result[0]) * (x - result[0]) + (result[1] - y) * (result[1] - y)));
|
||||
// result[2] = Double.parseDouble(formatNum);
|
||||
result[2] = CoordinateUtils.calculateLineDistance(result[0], result[1], x, y);
|
||||
// Log.d("getFootAndMinDistance", "计算距离--lon: "+result[0]+" lat: "+result[1]+" dis: "+result[2]);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user