What version of Traccar?
latest V6.5,2024.9
You cannot customize SQL queries on recent versions of Traccar. You have to change the source code.
Thanks a lot! I ask my friends help me change the source code ;
And after all done , I will post chang code , help someone also have this question;
I ask claude, and change F:\tmp\traccar\src\main\java\org\traccar\helper\model\PositionUtil.java
public static List<Position> getPositions( Storage storage, long deviceId, Date from, Date to) throws StorageException { return storage.getObjects(Position.class, new Request( new Columns.All(), new Condition.And( new Condition.Equals("deviceId", deviceId), new Condition.Between("fixTime", "from", from, "to", to)), new Order("fixTime")) .setTableName("tc_positions_3")); // Set custom table name here }
And now make the code
~/f/tmp/traccar$ ./gradlew assemble <-------------> 0% CONFIGURING [16s] > root project > Resolve dependencies of :classpath
Hope all is OK
I‘m Done!
cp src/main/java/org/traccar/model/Position.java src/main/java/org/traccar/model/Position3.java
And Change This
@StorageName("tc_positions_3") public class Position3 extends Position {
And Change this file:
src/main/java/org/traccar/helper/model/PositionUtil.java
import java.util.ArrayList; public static List<Position> getPositions( Storage storage, long deviceId, Date from, Date to) throws StorageException { List<Position3> positions3 = storage.getObjects(Position3.class, new Request( new Columns.All(), new Condition.And( new Condition.Equals("deviceId", deviceId), new Condition.Between("fixTime", "from", from, "to", to)), new Order("fixTime"))); // Convert List<Position3> to List<Position> return new ArrayList<>(positions3); }
And make it
./gradlew assemble --info
……………… > Task :assemble Skipping task ':assemble' as it has no actions. Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0. You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins. For more on this, please refer to https://docs.gradle.org/8.8/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation. BUILD SUCCESSFUL in 23s 7 actionable tasks: 3 executed, 4 up-to-date
And it's Work !!!!!!!!!!!!!!!!!!!!
Thanks Traccar And Thanks Anton Tananaev!
Hello,
I have already converted GPS coordinates to China GCJ-02 coordinates using a python script and stored them in the same database table
tc_positions_3
.Then, I want to select AMap (AutoNavi) for trajectory display and use the coordinate data from
tc_positions_3
. The coordinates reported by the devices are still inserted into thetc_positions
table. I have tried modifying the configuration file, like:<entry key='database.selectPositions'>SELECT * FROM tc_positions_3 WHERE deviceId = :deviceId AND fixTime BETWEEN :from AND :to ORDER BY fixTime</entry>
And restart service ,but it not work;
And also creating a database view (
CREATE VIEW tc_positions_view AS SELECT * FROM tc_positions_3;
), but neither method has worked.How can this be resolved? Do I need to modify the source code and compile it? I am not a developer, could you provide an example?
Thanks a lot!