x1ongzhu 6 éve
szülő
commit
25b6dbe87f

+ 2 - 2
src/main/java/com/izouma/walkchina/service/JourneyService.java

@@ -168,6 +168,7 @@ public class JourneyService {
         if (progress >= 1) {
             return;
         }
+        progress = needSteps * AppConstants.STEP_TO_DISTANCE_RATE / journeyStage.getDistance();
 
         List<Double> extracted = mapService.extractPolyline(journeyStage.getPolyline());
         Location location = mapService.endPoint(journeyStage.getRouteSteps(), journeyStage.getDistance() * progress, journeyStage.getPolyline());
@@ -181,8 +182,7 @@ public class JourneyService {
                                           .coin(coin)
                                           .originCoin(coin)
                                           .needProgress(progress)
-                                          .needSteps((long) (progress * journeyStage
-                                              .getDistance() / AppConstants.STEP_TO_DISTANCE_RATE))
+                                          .needSteps(needSteps)
                                           .received(false)
                                           .build();
         stageAwardRepository.save(stageAward);

+ 4 - 4
src/main/java/com/izouma/walkchina/service/MapService.java

@@ -197,7 +197,7 @@ public class MapService {
         int i = 0;
         for (; i < steps.size(); i++) {
             if (d + steps.get(i).getDistance() >= distance) {
-                sd = d + steps.get(i).getDistance() - distance;
+                sd = distance - d;
                 break;
             }
             d += steps.get(i).getDistance();
@@ -221,7 +221,7 @@ public class MapService {
             double lng2 = extracted.get(j + 3);
             double dd = LocationUtils.getDistance(lat1, lng1, lat2, lng2);
             if (d1 + dd >= sd) {
-                double p = (d1 + dd) / (d - steps.get(i).getDistance());
+                double p = (d1 + dd - sd) / dd;
                 double lat3 = (lat2 - lat1) * p + lat1;
                 double lng3 = (lng2 - lng1) * p + lng1;
                 subPolyline.add(lat3);
@@ -239,7 +239,7 @@ public class MapService {
         int i = 0;
         for (; i < steps.size(); i++) {
             if (d + steps.get(i).getDistance() >= distance) {
-                sd = d + steps.get(i).getDistance() - distance;
+                sd = distance - d;
                 break;
             }
             d += steps.get(i).getDistance();
@@ -257,7 +257,7 @@ public class MapService {
             double lng2 = extracted.get(j + 3);
             double dd = LocationUtils.getDistance(lat1, lng1, lat2, lng2);
             if (d1 + dd >= sd) {
-                double p = (d1 + dd) / (d - steps.get(i).getDistance());
+                double p = (d1 + dd - sd) / dd;
                 double lat3 = (lat2 - lat1) * p + lat1;
                 double lng3 = (lng2 - lng1) * p + lng1;
                 return new Location(lat3, lng3);

+ 1 - 1
src/main/java/com/izouma/walkchina/utils/LocationUtils.java

@@ -29,6 +29,6 @@ public class LocationUtils {
         s = s * EARTH_RADIUS;
         s = Math.round(s * 10000d) / 10000d;
         s = s * 1000;
-        return s;
+        return Math.abs(s);
     }
 }

+ 18 - 1
src/test/java/com/izouma/walkchina/service/MapServiceTest.java

@@ -1,7 +1,9 @@
 package com.izouma.walkchina.service;
 
 import com.google.gson.Gson;
+import com.izouma.walkchina.constant.AppConstants;
 import com.izouma.walkchina.domain.City;
+import com.izouma.walkchina.domain.JourneyStage;
 import com.izouma.walkchina.dto.Location;
 import com.izouma.walkchina.dto.webservice.DirectionResponse;
 import com.izouma.walkchina.repo.CityRepository;
@@ -44,7 +46,7 @@ public class MapServiceTest {
         City from = cityRepository.findOne(Example.of(City.builder().name("南京").build())).orElse(null);
         City to = cityRepository.findOne(Example.of(City.builder().name("扬州").build())).orElse(null);
         DirectionResponse response = mapService.direction(new Location(from.getLatitude(), from.getLongitude()),
-                new Location(to.getLatitude(), to.getLongitude()));
+                                                          new Location(to.getLatitude(), to.getLongitude()));
         System.out.println(new Gson().toJson(response));
     }
 
@@ -52,4 +54,19 @@ public class MapServiceTest {
     public void userMap() {
         mapService.userMap(677L);
     }
+
+    @Test
+    public void endPoint() {
+        JourneyStage stage = journeyStageRepository.findFirstByUserIdOrderByCreatedAtDesc(4263L).get();
+        Location location;
+
+        location = mapService.endPoint(stage.getRouteSteps(), 8000 * AppConstants.STEP_TO_DISTANCE_RATE, stage.getPolyline());
+        System.out.println(location.getLatitude() + "," + location.getLongitude());
+
+        location = mapService.endPoint(stage.getRouteSteps(), 9000 * AppConstants.STEP_TO_DISTANCE_RATE, stage.getPolyline());
+        System.out.println(location.getLatitude() + "," + location.getLongitude());
+
+        location = mapService.endPoint(stage.getRouteSteps(), 10000 * AppConstants.STEP_TO_DISTANCE_RATE, stage.getPolyline());
+        System.out.println(location.getLatitude() + "," + location.getLongitude());
+    }
 }