diff --git a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapViewWrapper.java b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapViewWrapper.java index 0c85d32f38..26b59a6e85 100644 --- a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapViewWrapper.java +++ b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapViewWrapper.java @@ -1045,6 +1045,7 @@ public class AMapViewWrapper implements IMogoMapView, 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()); } } @@ -1055,21 +1056,21 @@ public class AMapViewWrapper implements IMogoMapView, && !roadCache.getRoad().isEmpty() ) { start = System.currentTimeMillis(); double matchedPoint[] = PointInterpolatorUtil.mergeToRoad( wgs[0], wgs[1], roadCache.getRoad() ); - if(matchedPoint[2]<1) { - double diff = CoordinateUtils.calculateLineDistance(lon, lat, roadCache.getLastLon(), roadCache.getLastLon()); - if ((roadCache.getLastDistanceDiff() == 0 || roadCache.getLastDistanceDiff() > diff)) { - roadCache.setLastDistanceDiff(diff); + if(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"); + Log.i("timer-matchRoad-2", "cost " + (System.currentTimeMillis() - start) + "ms roadId: "+roadCache.getLastLat()); return matchRoad(id, lon, lat, angle, isGpsLocation, isRTK); }else{ + roadCacheMap.put(id, null); return matchedPoint; } } + roadCacheMap.put(id, null); return null; } diff --git a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/RoadCacheWrapper.java b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/RoadCacheWrapper.java index f64dc116c8..626a352d60 100644 --- a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/RoadCacheWrapper.java +++ b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/RoadCacheWrapper.java @@ -15,7 +15,7 @@ public class RoadCacheWrapper { private int roadLength = -1; public RoadCacheWrapper(List road) { - this.road = road; + setRoad(road); } public List getRoad() { @@ -51,4 +51,27 @@ public class RoadCacheWrapper { return 0; } + public boolean inCache(double lon, double lat) { + if (roadLength > 0) { + LonLatPoint start = road.get(0); + LonLatPoint end = road.get(roadLength - 1); + boolean latInRoad = false; + boolean lonInRoad = false; + if (start.getLatitude() > end.getLatitude()) { + latInRoad = lat <= start.getLatitude() && lat >= end.getLatitude(); + }else{ + latInRoad = lat >= start.getLatitude() && lat <= end.getLatitude(); + } + + if (start.getLongitude() > end.getLongitude()) { + lonInRoad = lon <= start.getLongitude() && lon >= end.getLongitude(); + }else{ + lonInRoad = lon >= start.getLongitude() && lon <= end.getLongitude(); + } + + return latInRoad && lonInRoad; + } + return false; + } + } diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/intent/MockIntentHandler.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/intent/MockIntentHandler.java index 02886b618e..438c078fc2 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/intent/MockIntentHandler.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/intent/MockIntentHandler.java @@ -560,9 +560,9 @@ public class MockIntentHandler implements IntentHandler { break; case 47: mLocationMockHandler.sendEmptyMessageDelayed( 1, 200L ); -// mLocationMockHandler.sendEmptyMessageDelayed( 2, 0 ); + mLocationMockHandler.sendEmptyMessageDelayed( 2, 0 ); // mLocationMockHandler.sendEmptyMessageDelayed( 21, 200 ); - mLocationMockHandler.sendEmptyMessageDelayed( 3, 0L ); +// mLocationMockHandler.sendEmptyMessageDelayed( 3, 0L ); // mLocationMockHandler.sendEmptyMessageDelayed( 5, 0L ); break; case 48: @@ -728,7 +728,7 @@ public class MockIntentHandler implements IntentHandler { private boolean handleMockSnapshotIntent() throws Exception { if ( br2 == null ) { - br2 = new BufferedReader( new InputStreamReader( AbsMogoApplication.getApp().getAssets().open( "snapshot2.txt" ) ) ); + br2 = new BufferedReader( new InputStreamReader( AbsMogoApplication.getApp().getAssets().open( "snapshot.txt" ) ) ); } String line = br2.readLine(); if ( line == null ) { @@ -756,7 +756,7 @@ public class MockIntentHandler implements IntentHandler { delay = cloudRoadData.getSystemTime() - last; } last = cloudRoadData.getSystemTime(); - mLocationMockHandler.sendEmptyMessageDelayed( 2, delay ); + mLocationMockHandler.sendEmptyMessageDelayed( 2, 100L ); return true; }