1. 程式人生 > >tile38 一款開源的geo 資料庫

tile38 一款開源的geo 資料庫

tile38 是基於golang 編寫的geo 資料庫,支援地理空間索引、實時地理圍欄,同時也支援leader-flower 的部署模型
備註: 下邊測試一個簡單的地理圍欄功能

環境準備

  • docker-compose 檔案
    包含了一個簡單的webhook 工具
 
version: "3"
services:
  app:
    image: tile38/tile38
    ports:
    - "9851:9851"
  benthos:
    image: jeffail/benthos
    volumes:
    - "./conf/webhook.yaml:/benthos.yaml"
    ports:
    - "4195:4195"
 

執行&&測試地理圍欄功能

啟動

docker-compose up -d

使用

  • 進入容器 app (tile38 服務)
docker-compose exec app sh
tile38-cli
 
  • 新增webhook格式
SETHOOK name endpoint [META name value ...] [EX seconds] NEARBY|WITHIN|INTERSECTS key FENCE [DETECT what] [COMMANDS which] param [param ...]
 
  • 新增資料圍欄:
/ # tile38-cli
127.0.0.1:9851> SETHOOK warehouse http://benthos:4195/ NEARBY fleet FENCE POINT 33.462 -112.268 6000
{"ok":true,"elapsed":"118.008µs"}
 
  • 新增進入圍欄區域的資料
SET fleet truck1 POINT 33.5123 -112.2693
  • webhook 資料
docker-compose logs -f benthos

效果

benthos_1 | get email message: {"command":"set","group":"5c395823b1e3cb00012724bc","detect":"enter","hook":"warehouse","key":"fleet","time":"2019-01-12T02:59:47.766263252Z","id":"dalong","object":{"type":"Point","coordinates":[-112.2693,33.5123]}}
benthos_1 | get email message: {"command":"set","group":"5c395823b1e3cb00012724bc","detect":"inside","hook":"warehouse","key":"fleet","time":"2019-01-12T02:59:47.766263252Z","id":"dalong","object":{"type":"Point","coordinates":[-112.2693,33.5123]}}

說明:
預設的webhook 資料會包含所有包含的型別,我們可以指定需要的型別

 
NEARBY fleet FENCE DETECT inside,outside POINT 33.462 -112.268 6000

說明

tile38 使用簡單,包含了rest 以及resp 協議的支援,同時webhook支援多種協議 http,https,redis,nats,grpc。。。

參考資料

https://tile38.com/topics/geofencing/
https://github.com/tidwall/tile38