Django通过jt808协议接收GPS数据,实现百度地图定位【多边形围栏】

1、主要功能:
  • 自动接收gps数据
  • 实时定位;
  • 设置多个电子围栏,超出并报警(批量设置围栏)
  • 多种模式可调
2. gps数据接收网络拓扑图(jt808/tcp协议)

在这里插入图片描述

3、图例展示:

1 .登录页面
在这里插入图片描述
2. 功能页面
在这里插入图片描述

  1. 后台管理
    在这里插入图片描述
4.关键代码

前端用原生javascript,后端为python-Django,关键代码如下:

<html>
<head>
    <title>智能定位</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <script src="./static/js/jquery.js"></script>
    <script type="text/javascript"
            src="http://api.map.baidu.com/api?v=2.0&ak=填入AK"></script>
    <script type="text/javascript" src="http://developer.baidu.com/map/custom/stylelist.js"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/library/GeoUtils/1.2/src/GeoUtils_min.js"></script>
    <script type="text/javascript"
            src="http://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.js"></script><!--加载鼠标绘制工具-->
    <script src="./static/js/jquery-1.9.1.js" type="text/javascript"></script>
    <script src="./static/js/index.js" type="text/javascript"></script>
    <link rel="stylesheet" href="http://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.css"/>
    <link rel="stylesheet" type="text/css" href="./static/css/index.css">

</head>
<body>

<div id="container" class="highlight"></div>

<div id="control">
    <table style="width:100%;color:#ffffff;background-color: #1890ff;">
        <tr>
            <!--<td colspan="2">-->
            <td colspan="2" style="color:#ffffff;background-color: #1890ff">
                功能操作区域:
            </td>
        </tr>
        <tr>
            <td>
                <button id="seleBtn" class="ant-btn .ant-btn-primary ant-btn-org">隐藏</button>
                <button id="resetBtn" class="ant-btn .ant-btn-primary ant-btn-green">重置</button>
                <button id="myBtn" class="ant-btn .ant-btn-primary ant-btn-red">清除</button>
                <div class="wrapper" style="display: inline-flex;">
                    <div class="tooltip" style="font-size: 14px;">上传电子围栏</div>
                    <label type="button" for="file" class="upload" style="padding: 2px 14px">
                        <span>选择</span>
                        <input type="file" id="file" onchange="jsReadFiles(this.files)">
                    </label>
                </div>
                <div style="display: inline-flex;position: fixed;right:15px;" class="closes wrapper" id="loginout">
                    X
                    <div class="tooltip" style="font-size: 14px;">退出</div>
                </div>
                <div style="display: inline-flex;" class="wrapper">
                    <div class="tooltip" style="font-size: 14px;">地图样式</div>

后端接收gps数据部分代码

import asyncore
import datetime
import json
import shelve

from jt808_analysis import jt808_analysis
import requests
import os, sys, django

base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(base_dir)

# DJANGO_SETTINGS_MODEL 环境变量
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'GpsServer.settings')
django.setup()
from app import models


class Jt808(asyncore.dispatcher_with_send):
    buffer_data = {} 
    def pre_handle(self, datas):
        data_handled = []
        if datas.startswith(b'~') and datas.endswith(b'~'):
            datas = datas.split(b'~')
            datas.pop()
            for data in datas:
                if data != b'':
                    data = b'~' + data + b'~'
                    data_handled.append(data)
            return data_handled
        else:
            return 'buffer_data' 
    def handle_save(sefl, data):
        handle_data = []
        if data.get('all_loca') == None: 
            handle_data.append(data)
        else: 
            handle_data = res['all_loca'] 
        for res in handle_data:
            with shelve.open('device') as db:
                device = db.get(res['device_id'], {})
                device['dynamic'] = res
                device['device_id'] = res.get('device_id')
                lng = res.get('lng', '0')
                lat = res.get('lat', '0')
                if lng != '0' and lat != '0':
                    device['lng'] = lng
                    device['lat'] = lat
                db[res['device_id']] = device
            with shelve.open(res['device_id']) as db:
                data_id = int(db.get('id', '0')) + 1
                db[str(data_id)] = res
                db['id'] = str(data_id)
5.最后附上代码下载地址: 传送门

有啥问题可以私信我,最后祝您观文愉快!!!

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Starry-sky(jing)

一起共勉,一起加油!!!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值