Skip to content

Commit

Permalink
feat: baidumap offset
Browse files Browse the repository at this point in the history
  • Loading branch information
h7ml committed Jul 1, 2022
1 parent 20b1b6c commit a79dbc7
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 17 deletions.
72 changes: 57 additions & 15 deletions apps/dgiot_dlink/priv/swagger/swagger_dlink.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@
]
}
},
"/topic":{
"post":{
"/topic": {
"post": {
"summary": "订阅topic",
"description":"订阅topic",
"description": "订阅topic",
"parameters": [
{
"in": "body",
Expand All @@ -112,24 +112,66 @@
}
}
],
"responses":{
"200":{
"description":"Returns operation status"
"responses": {
"200": {
"description": "Returns operation status"
},
"400":{
"description":"Bad Request"
"400": {
"description": "Bad Request"
},
"401":{
"description":"Unauthorized"
"401": {
"description": "Unauthorized"
},
"403":{
"description":"Forbidden"
"403": {
"description": "Forbidden"
},
"500":{
"description":"Server Internal error"
"500": {
"description": "Server Internal error"
}
},
"tags":[
"tags": [
"Dlink"
]
}
},
"/thingecho": {
"get": {
"summary": "物模型",
"description": "物模型回显",
"parameters": [
{
"in": "query",
"name": "productid",
"type": "string",
"description": "产品id",
"required": true
},
{
"in": "query",
"name": "identifier",
"type": "string",
"description": "物模型标识符",
"required": true
}
],
"responses": {
"200": {
"description": "Returns operation status"
},
"400": {
"description": "Bad Request"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"500": {
"description": "Server Internal error"
}
},
"tags": [
"Dlink"
]
}
Expand Down
6 changes: 5 additions & 1 deletion apps/dgiot_dlink/src/handler/dgiot_dlink_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ do_request(post_topic, #{<<"topic">> := Topic} = _Args, #{<<"sessionToken">> :=
),
dgiot_data:insert({page_router_key, SessionToken, TopicKey}, Topic),
timer:sleep(10),
{200, #{<<"message">> => <<"订阅成功"/utf8>>, <<"Topic">> => Topic, <<"TopicKey">> => TopicKey}} ;
{200, #{<<"message">> => <<"订阅成功"/utf8>>, <<"Topic">> => Topic, <<"TopicKey">> => TopicKey}};
false ->
[_Head, _User, Key | _] = re:split(Topic, "/"),
TopicKey = <<"dg_user_", Key/binary>>,
Expand All @@ -151,5 +151,9 @@ do_request(post_topic, #{<<"topic">> := Topic} = _Args, #{<<"sessionToken">> :=
{200, #{<<"message">> => <<"订阅成功"/utf8>>, <<"Topic">> => Topic, <<"TopicKey">> => TopicKey}}
end;

do_request(get_thingecho, _Args, _Context, _Req) ->
%% 发送mqtt消息
{200, <<"success">>};

do_request(_OperationId, _Args, _Context, _Req) ->
{error, <<"Not Allowed.">>}.
4 changes: 4 additions & 0 deletions apps/dgiot_http/etc/dgiot_http.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ aliyun.uploadHost= http://dgiotpump.oss-cn-shanghai.aliyuncs.com

#百度地图
baidumap.appkey = 4vrccSabIaHEtLn6GZzFCUYfVjqWR7r7
#百度地图纠偏值
baidumap.lngoffset = 0.00002
baidumap.latoffset = 0.00001


#友盟消息推送
umeng.appkey = 5f8bfc1780455950e4ad0482
Expand Down
14 changes: 14 additions & 0 deletions apps/dgiot_http/priv/dgiot_http.schema
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@
{datatype, string}
]}.

%%--------------------------------------------------------------------
%% 百度地图纠偏值
%%--------------------------------------------------------------------

{mapping, "baidumap.lngoffset", "dgiot_http.baidumap_lngoffset", [
{default, "0.00002"},
{datatype, string}
]}.

{mapping, "baidumap.latoffset", "dgiot_http.baidumap_latoffset", [
{default, "0.00001"},
{datatype, string}
]}.

%%--------------------------------------------------------------------
%% 友盟消息推送配置
%%--------------------------------------------------------------------
Expand Down
5 changes: 4 additions & 1 deletion apps/dgiot_http/src/baidu/dgiot_gps.erl
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,12 @@ get_deng_gps(Lng, Lat) ->
[LngDeg, LatDeg].

get_baidu_gps(LonDeg, LatDeg) ->
Latoffset = dgiot_utils:to_float(application:get_env(dgiot_http, baidumap_latoffset, <<"-0.0002">>)),
Lngoffset = dgiot_utils:to_float(application:get_env(dgiot_http, baidumap_lngoffset, <<"-0.0000">>)),
[Mglng, Mglat] = wgs84togcj02(LonDeg, LatDeg),
[Bd_lng, Bd_lat] = gcj02tobd09(Mglng, Mglat),
[dgiot_utils:to_float(Bd_lng, 6), dgiot_utils:to_float(Bd_lat - 0.0002, 6)].
%% 定位偏移值,使用当前gps解析值,加上偏移值,偏移值可为负数
[dgiot_utils:to_float(Bd_lng + Lngoffset, 6), dgiot_utils:to_float(Bd_lat + Latoffset, 6)].

get_baidu_gps(LonDeg, LatDeg, Lonoffset, Latoffset) ->
[Mglng, Mglat] = wgs84togcj02(LonDeg, LatDeg),
Expand Down

0 comments on commit a79dbc7

Please sign in to comment.