当前位置: 首页 > news >正文

基于SpringBoot+WebSocket实现地图上绘制车辆实时运动轨迹图

实现基于北斗卫星的车辆定位和轨迹图的Maven工程(使用模拟数据),我们将使用以下技术:

  • Spring Boot:作为后端框架,用来提供数据接口。
  • Thymeleaf:作为前端模板引擎,呈现网页。
  • Leaflet.js:一个开源的JavaScript库,用于显示交互式地图。
  • Simulated Data:使用随机生成的模拟GPS数据来模拟北斗卫星车辆位置。
  • WebSocket:用于实现实时数据推送,确保地图位置每秒更新。

目录

1. 项目结构

2. Maven依赖配置 (pom.xml)

3. 实现后端服务

3.1 BeidouApplication.java

4. 配置文件 (application.properties)

5. 启动项目

6. 访问页面


1. 项目结构

创建一个Maven项目,基本结构如下:

项目结构图: 

2. Maven依赖配置 (pom.xml)

首先在pom.xml中添加必要的依赖,确保使用Spring Boot、WebSocket和Thymeleaf:

<dependencies><!-- Spring Boot --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- Thymeleaf for rendering HTML --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency><!-- WebSocket for real-time communication --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-websocket</artifactId></dependency><!-- Lombok (Optional, for cleaner code) --><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><scope>provided</scope></dependency>
</dependencies>

3. 实现后端服务

3.1 BeidouApplication.java

这是Spring Boot的启动类:

package com.example.beidou;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class BeidouApplication {public static void main(String[] args) {SpringApplication.run(BeidouApplication.class, args);}
}

4. 配置文件 (application.properties)

server.port=8080

5. 启动项目

确保你有Java和Maven环境,在项目根目录执行以下命令启动应用:

mvn spring-boot:run

6. 访问页面

在浏览器中访问 http://localhost:8080,你应该可以看到一个地图,显示车辆的实时位置和轨迹更新。

效果图:

 Controller:

package com.example.beidou.controller;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;@RestController
public class VehicleController {private ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);@Autowiredprivate SimpMessagingTemplate messagingTemplate;private Map<String, Map<String, Double>> vehiclePositions = new HashMap<String, Map<String, Double>>() {{put("Vehicle 1", new HashMap<String, Double>() {{put("latitude", 39.9042);//北京put("longitude", 116.4074);}});put("Vehicle 2", new HashMap<String, Double>() {{put("latitude", 31.2304);//上海put("longitude", 121.4737);}});put("Vehicle 3", new HashMap<String, Double>() {{put("latitude", 22.3964);// 香港put("longitude", 114.1095);}});put("Vehicle 4", new HashMap<String, Double>() {{put("latitude", 30.5728);//成都put("longitude", 104.0668);}});put("Vehicle 5", new HashMap<String, Double>() {{put("latitude", 34.3416);// 西安put("longitude", 108.9398);}});}};private Map<String, Map<String, Double>> vehicleTargets = new HashMap<String, Map<String, Double>>() {{put("Vehicle 1", new HashMap<String, Double>() {{put("latitude", 31.2304);//上海put("longitude", 121.4737);}});put("Vehicle 2", new HashMap<String, Double>() {{put("latitude", 39.9042);//北京put("longitude", 116.4074);}});put("Vehicle 3", new HashMap<String, Double>() {{put("latitude", 34.3416);// 西安put("longitude", 108.9398);}});put("Vehicle 4", new HashMap<String, Double>() {{put("latitude", 22.3964);// 香港put("longitude", 114.1095);}});put("Vehicle 5", new HashMap<String, Double>() {{put("latitude", 30.5728);//成都put("longitude", 104.0668);}});}};@GetMapping("/startSimulation")public String startSimulation() {executorService.scheduleAtFixedRate(this::sendVehicleUpdates, 0, 500, TimeUnit.MILLISECONDS);return "Simulation started!";}@GetMapping("/stopSimulation")public String stopSimulation() {executorService.shutdownNow();return "Simulation stopped!";}private void sendVehicleUpdates() {Map<String, Map<String, Double>> updatedPositions = new HashMap<>();for (Map.Entry<String, Map<String, Double>> entry : vehiclePositions.entrySet()) {String vehicleId = entry.getKey();Map<String, Double> position = entry.getValue();Map<String, Double> target = vehicleTargets.get(vehicleId);// 按一定速度向目标移动double latDiff = target.get("latitude") - position.get("latitude");double lonDiff = target.get("longitude") - position.get("longitude");// 每次移动经纬度的 1/100double newLatitude = position.get("latitude") + latDiff * 0.02;double newLongitude = position.get("longitude") + lonDiff * 0.02;position.put("latitude", newLatitude);position.put("longitude", newLongitude);updatedPositions.put(vehicleId, new HashMap<>(position));}messagingTemplate.convertAndSend("/topic/vehicleLocation", updatedPositions);}
}

WebSocketConfig:
package com.example.beidou.config;import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {@Overridepublic void configureMessageBroker(MessageBrokerRegistry config) {config.enableSimpleBroker("/topic");config.setApplicationDestinationPrefixes("/app");}@Overridepublic void registerStompEndpoints(StompEndpointRegistry registry) {registry.addEndpoint("/vehicle-location").setAllowedOriginPatterns("*").withSockJS();}
}

前端页面代码有需要的,请私信我,有偿提供代码,白嫖党勿扰! 

相关文章:

基于SpringBoot+WebSocket实现地图上绘制车辆实时运动轨迹图

实现基于北斗卫星的车辆定位和轨迹图的Maven工程&#xff08;使用模拟数据&#xff09;&#xff0c;我们将使用以下技术&#xff1a; Spring Boot&#xff1a;作为后端框架&#xff0c;用来提供数据接口。Thymeleaf&#xff1a;作为前端模板引擎&#xff0c;呈现网页。Leaflet…...

嵌入式入门小工程

此代码基于s3c2440 1.点灯 //led.c void init_led(void) {unsigned int t;t GPBCON;t & ~((3 << 10) | (3 << 12) | (3 << 14) | (3 << 16));t | (1 << 10) | (1 << 12) | (1 << 14) | (1 << 16);GPBCON t; }void le…...

hackmyvm靶场--zon

环境 攻击机kali 靶机 未知 主机探测 因为在同一个局域网内使用ARP协议探测存活主机 靶机为192.168.56.128 端口探测 常见的80和22端口 那么一定是寻找web漏洞拿shell了 后台扫描 后台扫描常用dirsearch和gobuster,有时候小字典可能不太行&#xff0c;可以尝试换个大点…...

atcoder abc372 启发式合并, dp

A delete 代码&#xff1a; #include <bits.stdc.h>using namespace std;int main() {string s;cin >> s;for(auto t: s) if(t ! .) cout << t; } B 3 ^ A 思路&#xff1a;三进制转换&#xff0c;可以参考二进制&#xff0c;先把当前可以加入的最大的3的…...

CentOS Stream 9部署MariaDB

1、更新系统软件包 sudo dnf update 2、安装MariaDB软件包&#xff08;替代mysql&#xff09; sudo dnf install mariadb-server 3、安装MariaDB服务 sudo systemctl enable --now mariadb 4、检查MariaDB服务状态 sudo systemctl status mariadb 5、配置MariaDB安全性 sudo my…...

【Leetcode:997. 找到小镇的法官 + 入度出度】

&#x1f680; 算法题 &#x1f680; &#x1f332; 算法刷题专栏 | 面试必备算法 | 面试高频算法 &#x1f340; &#x1f332; 越难的东西,越要努力坚持&#xff0c;因为它具有很高的价值&#xff0c;算法就是这样✨ &#x1f332; 作者简介&#xff1a;硕风和炜&#xff0c;…...

大数据Flink(一百二十三):五分钟上手Flink MySQL连接器

文章目录 五分钟上手Flink MySQL连接器 一、创建数据库表 二、​​​​​​创建session集群 三、源表查询 四、​​​​​窗口计算 五、​​​​​​结果数据写回数据库 五分钟上手Flink MySQL连接器 MySQL Connector可以将本地或远程的MySQL数据库连接到Flink中&#x…...

SYN Flood攻击原理,SYN Cookie算法

SYN Flood是一种非常危险而常见的Dos攻击方式。到目前为止&#xff0c;能够有效防范SYN Flood攻击的手段并不多&#xff0c;SYN Cookie就是其中最著名的一种。 1. SYN Flood攻击原理 SYN Flood攻击是一种典型的拒绝服务(Denial of Service)攻击。所谓的拒绝服务攻击就是通过进…...

计组(蒋)期末速成笔记1

蒋本珊计组期末不挂科复习笔记 第1章 概论 第2章 数据的机器层次表示 第3章 指令系统 第4章 数值的机器运算 第5章 存储系统和结构 第6章 中央处理器 第7章 总线 第1章 概论 蒋本珊计组期末不挂科复习笔记知道你快考试了&#xff0c;莫慌&#xff01; 第1章 概论1.1 冯诺依曼计…...

mysql学习教程,从入门到精通,SQL 更新数据(UPDATE 语句)(17)

1、SQL 更新数据&#xff08;UPDATE 语句&#xff09; SQL UPDATE 需要指定要更新的表、要修改的列以及新值&#xff0c;并且通常会通过WHERE子句来指定哪些行需要被更新。下面是一个简单的示例&#xff0c;说明如何使用UPDATE语句。 假设我们有一个名为employees的表&#xf…...

【吊打面试官系列-MySQL面试题】MyISAM 表格将在哪里存储,并且还提供其存储格式?

大家好&#xff0c;我是锋哥。今天分享关于【MyISAM 表格将在哪里存储&#xff0c;并且还提供其存储格式&#xff1f;】面试题&#xff0c;希望对大家有帮助&#xff1b; MyISAM 表格将在哪里存储&#xff0c;并且还提供其存储格式&#xff1f; 每个 MyISAM 表格以三种格式存储…...

常用的图像增强的算法之间的联系和区别

Unsharp Mask (USM)、拉普拉斯算子、直方图均衡化和伽马增强是图像处理中常见的技术&#xff0c;但它们在原理、作用和应用场景上有显著不同。以下是对这些方法的详细比较&#xff1a; 1. Unsharp Mask (USM) 原理&#xff1a;USM 是通过对图像进行模糊处理&#xff08;如高斯…...

SpringBoot+Vue考试系统免费分享

源码说明&#xff1a; 这是一个开源的SpringBoot与Vue开发的在线考试系统。经过站长测试&#xff0c;系统稳定可用&#xff0c;允许重复考试。 环境&#xff1a; 需要安装的环境包括Node.js v14.21.3、JDK8、Maven以及MySQL 5.7。 前端部署教程&#xff1a; 执行 npm inst…...

音视频入门基础:FLV专题(1)——FLV官方文档下载

一、FLV简介 Flash Video&#xff08;简称FLV&#xff09;&#xff0c;是一种网络视频格式&#xff0c;用作流媒体格式&#xff0c;它的出现有效地解决了视频文件导入Flash后&#xff0c;使导出的SWF文件体积庞大&#xff0c;不能在网络上有效使用等缺点。 一般FLV文件包在SW…...

使用c#制作一个小型桌面程序

封装dll 首先使用visual stdio 创建Dll新项目,然后属性管理器导入自己的工程属性表&#xff08;如果没有可以参考visual stdio 如何配置opencv等其他环境&#xff09; 创建完成后 系统会自动生成一些文件&#xff0c;其中 pch.cpp 先不要修改&#xff0c;pch.h中先导入自己需…...

Clip studio paint百度云下载:附安装包+教程

首先补一个介绍&#xff0c;Clip Studio Paint&#xff08;即CSP&#xff09;&#xff1a;这是一款专业的绘画和漫画创作软件&#xff0c;拥有丰富的绘画工具&#xff0c;适合漫画创作者使用。其界面友好&#xff0c;工具齐全&#xff0c;能够满足漫画创作中的各种需求。 用过…...

从Yargs源码学习中间件的设计

yargs中间件介绍 yargs 是一个用于解析命令行参数的流行库&#xff0c;它能帮助开发者轻松地定义 CLI&#xff08;命令行接口&#xff09;&#xff0c;并提供参数处理、命令组织、help文本自动生成等功能。今天我们来学习一下它对中间件的支持。 中间件的API详细信息&#xff0…...

高级I/O知识分享【epoll || Reactor ET,LT模式】

博客主页&#xff1a;花果山~程序猿-CSDN博客 文章分栏&#xff1a;Linux_花果山~程序猿的博客-CSDN博客 关注我一起学习&#xff0c;一起进步&#xff0c;一起探索编程的无限可能吧&#xff01;让我们一起努力&#xff0c;一起成长&#xff01; 目录 一&#xff0c;接口 epo…...

Matlab 的.m 文件批量转成py文件

在工作中碰到了一个问题&#xff0c;需要将原来用matlab gui做出来的程序改为python程序&#xff0c;因为涉及到很多文件&#xff0c;所以在网上搜了搜有没有直接能转化的库。参考了【Matlab】一键Matlab代码转python代码详细教程_matlab2python-CSDN博客 这位博主提到的matla…...

【软考】传输层协议TCP与UDP

目录 1. TCP1.1 说明1.2 三次握手 2. UDP3. 例题3.1 例题1 1. TCP 1.1 说明 1.TCP(Transmission Control Protocol&#xff0c;传输控制协议)是整个 TCP/IP 协议族中最重要的协议之一。2.它在IP提供的不可靠数据服务的基础上为应用程序提供了一个可靠的、面向连接的、全双工的…...

基于FPGA的PID算法学习———实现PID比例控制算法

基于FPGA的PID算法学习 前言一、PID算法分析二、PID仿真分析1. PID代码2.PI代码3.P代码4.顶层5.测试文件6.仿真波形 总结 前言 学习内容&#xff1a;参考网站&#xff1a; PID算法控制 PID即&#xff1a;Proportional&#xff08;比例&#xff09;、Integral&#xff08;积分&…...

R语言AI模型部署方案:精准离线运行详解

R语言AI模型部署方案:精准离线运行详解 一、项目概述 本文将构建一个完整的R语言AI部署解决方案,实现鸢尾花分类模型的训练、保存、离线部署和预测功能。核心特点: 100%离线运行能力自包含环境依赖生产级错误处理跨平台兼容性模型版本管理# 文件结构说明 Iris_AI_Deployme…...

java 实现excel文件转pdf | 无水印 | 无限制

文章目录 目录 文章目录 前言 1.项目远程仓库配置 2.pom文件引入相关依赖 3.代码破解 二、Excel转PDF 1.代码实现 2.Aspose.License.xml 授权文件 总结 前言 java处理excel转pdf一直没找到什么好用的免费jar包工具,自己手写的难度,恐怕高级程序员花费一年的事件,也…...

对WWDC 2025 Keynote 内容的预测

借助我们以往对苹果公司发展路径的深入研究经验&#xff0c;以及大语言模型的分析能力&#xff0c;我们系统梳理了多年来苹果 WWDC 主题演讲的规律。在 WWDC 2025 即将揭幕之际&#xff0c;我们让 ChatGPT 对今年的 Keynote 内容进行了一个初步预测&#xff0c;聊作存档。等到明…...

Cinnamon修改面板小工具图标

Cinnamon开始菜单-CSDN博客 设置模块都是做好的&#xff0c;比GNOME简单得多&#xff01; 在 applet.js 里增加 const Settings imports.ui.settings;this.settings new Settings.AppletSettings(this, HTYMenusonichy, instance_id); this.settings.bind(menu-icon, menu…...

鸿蒙中用HarmonyOS SDK应用服务 HarmonyOS5开发一个医院查看报告小程序

一、开发环境准备 ​​工具安装​​&#xff1a; 下载安装DevEco Studio 4.0&#xff08;支持HarmonyOS 5&#xff09;配置HarmonyOS SDK 5.0确保Node.js版本≥14 ​​项目初始化​​&#xff1a; ohpm init harmony/hospital-report-app 二、核心功能模块实现 1. 报告列表…...

从零实现STL哈希容器:unordered_map/unordered_set封装详解

本篇文章是对C学习的STL哈希容器自主实现部分的学习分享 希望也能为你带来些帮助~ 那咱们废话不多说&#xff0c;直接开始吧&#xff01; 一、源码结构分析 1. SGISTL30实现剖析 // hash_set核心结构 template <class Value, class HashFcn, ...> class hash_set {ty…...

NLP学习路线图(二十三):长短期记忆网络(LSTM)

在自然语言处理(NLP)领域,我们时刻面临着处理序列数据的核心挑战。无论是理解句子的结构、分析文本的情感,还是实现语言的翻译,都需要模型能够捕捉词语之间依时序产生的复杂依赖关系。传统的神经网络结构在处理这种序列依赖时显得力不从心,而循环神经网络(RNN) 曾被视为…...

SpringTask-03.入门案例

一.入门案例 启动类&#xff1a; package com.sky;import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cache.annotation.EnableCach…...

Web 架构之 CDN 加速原理与落地实践

文章目录 一、思维导图二、正文内容&#xff08;一&#xff09;CDN 基础概念1. 定义2. 组成部分 &#xff08;二&#xff09;CDN 加速原理1. 请求路由2. 内容缓存3. 内容更新 &#xff08;三&#xff09;CDN 落地实践1. 选择 CDN 服务商2. 配置 CDN3. 集成到 Web 架构 &#xf…...