diff --git a/src/main/java/org/traccar/web/server/model/ImportServlet.java b/src/main/java/org/traccar/web/server/model/ImportServlet.java index 69b51df8..0b8ecef0 100644 --- a/src/main/java/org/traccar/web/server/model/ImportServlet.java +++ b/src/main/java/org/traccar/web/server/model/ImportServlet.java @@ -111,6 +111,7 @@ void gpx(Device device, InputStream inputStream, HttpServletResponse response) t List parsedPositions = new LinkedList(); Position position = null; + Position latestPosition = null; response.getWriter().println("
");
 
@@ -155,6 +156,9 @@ void gpx(Device device, InputStream inputStream, HttpServletResponse response) t
                            xsr.getLocalName().equalsIgnoreCase("trkpt")) {
 
                     parsedPositions.add(position);
+                    if (latestPosition == null || position.getTime().compareTo(position.getTime()) < 0) {
+                        latestPosition = position;
+                    }
                     position = null;
                 }
             }
@@ -196,6 +200,10 @@ void gpx(Device device, InputStream inputStream, HttpServletResponse response) t
                 }
             }
 
+            if (latestPosition != null && device.getLatestPosition() == null || device.getLatestPosition().getTime().compareTo(latestPosition.getTime()) < 0) {
+                device.setLatestPosition(latestPosition);
+            }
+
             response.getWriter().println("Already exist: " + (parsedPositions.size() - imported));
             response.getWriter().println("Imported: " + imported);