Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
D-GSQ
uni-app
提交
8c312f00
U
uni-app
项目概览
D-GSQ
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8c312f00
编写于
10月 19, 2022
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(location update): 修复回调及监听事件触发错误并调整默认坐标系为gcj02
上级
23f1c944
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
98 addition
and
111 deletion
+98
-111
src/platforms/app-plus/service/api/location/location-change.js
...latforms/app-plus/service/api/location/location-change.js
+40
-45
src/platforms/h5/service/api/location/location-change.js
src/platforms/h5/service/api/location/location-change.js
+58
-66
未找到文件。
src/platforms/app-plus/service/api/location/location-change.js
浏览文件 @
8c312f00
import
{
invoke
}
from
'
../../bridge
'
import
{
invoke
}
from
'
../../bridge
'
const
callbackIds
=
[]
const
callbackOnErrorIds
=
[]
const
callbackOffErrorIds
=
[]
let
watchId
/**
let
successCallbackIds
=
[]
* 开始更新定位
let
errorCallbackIds
=
[]
*/
let
started
=
false
export
function
startLocationUpdate
({
type
=
'
wgs84
'
})
{
let
watchId
=
0
watchId
=
plus
.
geolocation
.
watchPosition
(
export
function
startLocationUpdate
({
type
=
'
gcj02
'
},
callbackId
)
{
watchId
=
watchId
||
plus
.
geolocation
.
watchPosition
(
res
=>
{
res
=>
{
callbackIds
.
forEach
(
callbackId
=>
{
started
=
true
successCallbackIds
.
forEach
(
callbackId
=>
{
invoke
(
callbackId
,
res
.
coords
)
invoke
(
callbackId
,
res
.
coords
)
})
})
},
},
error
=>
{
error
=>
{
callbackOnErrorIds
.
forEach
(
callbackId
=>
{
if
(
!
started
)
{
invoke
(
callbackId
,
{
errMsg
:
`startLocationUpdate:fail
${
error
.
message
}
`
})
started
=
true
}
errorCallbackIds
.
forEach
(
callbackId
=>
{
invoke
(
callbackId
,
{
invoke
(
callbackId
,
{
errMsg
:
'
onLocationChange:fail
'
+
error
.
message
errMsg
:
`onLocationChange:fail
${
error
.
message
}
`
})
})
})
})
},
},
...
@@ -25,56 +28,48 @@ export function startLocationUpdate ({ type = 'wgs84' }) {
...
@@ -25,56 +28,48 @@ export function startLocationUpdate ({ type = 'wgs84' }) {
coordsType
:
type
coordsType
:
type
}
}
)
)
setTimeout
(()
=>
{
invoke
(
callbackId
,
{
errMsg
:
'
startLocationUpdate:ok
'
})
},
100
)
}
}
/**
export
function
stopLocationUpdate
()
{
* 暂停更新定位
if
(
watchId
!==
0
)
{
* @param {*} callbackId
*/
export
function
stopLocationUpdate
(
callbackId
)
{
if
(
watchId
)
{
plus
.
geolocation
.
clearWatch
(
watchId
)
plus
.
geolocation
.
clearWatch
(
watchId
)
}
else
{
started
=
false
invoke
(
callbackId
,
{
errMsg
:
'
stopLocationUpdate:fail
'
})
watchId
=
0
}
}
return
{}
return
{}
}
}
/**
* 监听更新定位
* @param {*} callbackId
*/
export
function
onLocationChange
(
callbackId
)
{
export
function
onLocationChange
(
callbackId
)
{
callbackIds
.
push
(
callbackId
)
successCallbackIds
.
push
(
callbackId
)
}
/**
* 监听更新定位失败
* @param {*} callbackId
*/
export
function
onLocationChangeError
(
callbackId
)
{
callbackOnErrorIds
.
push
(
callbackId
)
}
}
// 移除实时地理位置变化事件的监听函数
export
function
offLocationChange
(
callbackId
)
{
export
function
offLocationChange
(
callbackId
)
{
if
(
callbackId
)
{
if
(
callbackId
)
{
const
index
=
c
allbackIds
.
indexOf
(
callbackId
)
const
index
=
successC
allbackIds
.
indexOf
(
callbackId
)
if
(
index
>=
0
)
{
if
(
index
>=
0
)
{
callbackIds
.
splice
(
index
,
1
)
successCallbackIds
.
splice
(
index
,
1
)
}
else
{
callbackOffErrorIds
.
forEach
(
callbackId
=>
{
invoke
(
callbackId
,
{
errMsg
:
'
offLocationChange:fail
'
})
})
}
}
}
else
{
}
else
{
callbackIds
.
length
=
0
successCallbackIds
=
[]
}
}
}
}
// 移除实时地理位置变化事件的监听函数
export
function
onLocationChangeError
(
callbackId
)
{
errorCallbackIds
.
push
(
callbackId
)
}
export
function
offLocationChangeError
(
callbackId
)
{
export
function
offLocationChangeError
(
callbackId
)
{
callbackOffErrorIds
.
push
(
callbackId
)
if
(
callbackId
)
{
const
index
=
errorCallbackIds
.
indexOf
(
callbackId
)
if
(
index
>=
0
)
{
errorCallbackIds
.
splice
(
index
,
1
)
}
}
else
{
errorCallbackIds
=
[]
}
}
}
src/platforms/h5/service/api/location/location-change.js
浏览文件 @
8c312f00
import
{
translateGeo
}
from
'
../../../helpers/location
'
import
{
translateGeo
}
from
'
../../../helpers/location
'
const
{
invokeCallbackHandler
:
invoke
}
=
UniServiceJSBridge
const
{
invokeCallbackHandler
:
invoke
}
=
UniServiceJSBridge
const
c
allbackIds
=
[]
let
successC
allbackIds
=
[]
const
callbackOnError
Ids
=
[]
let
errorCallback
Ids
=
[]
const
callbackOffErrorIds
=
[]
let
started
=
false
let
watchId
let
watchId
=
0
/**
export
function
startLocationUpdate
({
type
=
'
gcj02
'
},
callbackId
)
{
* 开始更新定位
if
(
!
navigator
.
geolocation
)
{
*/
return
{
export
function
startLocationUpdate
({
type
=
'
wgs84
'
})
{
errMsg
:
'
startLocationUpdate:fail
'
if
(
navigator
.
geolocation
)
{
}
watchId
=
navigator
.
geolocation
.
watchPosition
(
}
res
=>
{
translateGeo
(
type
,
res
.
coords
)
watchId
=
watchId
||
navigator
.
geolocation
.
watchPosition
(
.
then
((
coords
)
=>
{
res
=>
{
callbackIds
.
forEach
(
callbackId
=>
{
started
=
true
invoke
(
callbackId
,
coords
)
translateGeo
(
type
,
res
.
coords
)
})
.
then
((
coords
)
=>
{
}).
catch
(
error
=>
{
successCallbackIds
.
forEach
(
callbackId
=>
{
callbackOnErrorIds
.
forEach
(
callbackId
=>
{
invoke
(
callbackId
,
coords
)
invoke
(
callbackId
,
{
errMsg
:
'
onLocationChange:fail
'
+
error
.
message
})
})
})
})
},
}).
catch
(
error
=>
{
error
=>
{
errorCallbackIds
.
forEach
(
callbackId
=>
{
callbackOnErrorIds
.
forEach
(
callbackId
=>
{
invoke
(
callbackId
,
{
invoke
(
callbackId
,
{
errMsg
:
`onLocationChange:fail
${
error
.
message
}
`
errMsg
:
'
onLocationChange:fail
'
+
error
.
message
})
})
})
})
})
},
error
=>
{
if
(
!
started
)
{
invoke
(
callbackId
,
{
errMsg
:
`startLocationUpdate:fail
${
error
.
message
}
`
})
started
=
true
}
}
)
errorCallbackIds
.
forEach
(
callbackId
=>
{
}
else
{
invoke
(
callbackId
,
{
callbackOnErrorIds
.
forEach
(
callbackId
=>
{
errMsg
:
`onLocationChange:fail
${
error
.
message
}
`
invoke
(
callbackId
,
{
})
errMsg
:
'
onLocationChange:fail device nonsupport geolocation
'
})
})
}
)
setTimeout
(()
=>
{
invoke
(
callbackId
,
{
errMsg
:
'
startLocationUpdate:ok
'
})
})
}
}
,
100
)
}
}
/**
export
function
stopLocationUpdate
()
{
* 暂停更新定位
if
(
watchId
!==
0
)
{
* @param {*} callbackId
*/
export
function
stopLocationUpdate
(
callbackId
)
{
if
(
watchId
)
{
navigator
.
geolocation
.
clearWatch
(
watchId
)
navigator
.
geolocation
.
clearWatch
(
watchId
)
}
else
{
started
=
false
invoke
(
callbackId
,
{
errMsg
:
'
stopLocationUpdate:fail
'
})
watchId
=
0
}
}
return
{}
return
{}
}
}
/**
* 监听更新定位
* @param {*} callbackId
*/
export
function
onLocationChange
(
callbackId
)
{
export
function
onLocationChange
(
callbackId
)
{
callbackIds
.
push
(
callbackId
)
successCallbackIds
.
push
(
callbackId
)
}
/**
* 监听更新定位失败
* @param {*} callbackId
*/
export
function
onLocationChangeError
(
callbackId
)
{
callbackOnErrorIds
.
push
(
callbackId
)
}
}
// 移除实时地理位置变化事件的监听函数
export
function
offLocationChange
(
callbackId
)
{
export
function
offLocationChange
(
callbackId
)
{
if
(
callbackId
)
{
if
(
callbackId
)
{
const
index
=
c
allbackIds
.
indexOf
(
callbackId
)
const
index
=
successC
allbackIds
.
indexOf
(
callbackId
)
if
(
index
>=
0
)
{
if
(
index
>=
0
)
{
callbackIds
.
splice
(
index
,
1
)
successCallbackIds
.
splice
(
index
,
1
)
}
else
{
callbackOffErrorIds
.
forEach
(
callbackId
=>
{
invoke
(
callbackId
,
{
errMsg
:
'
offLocationChange:fail
'
})
})
}
}
}
else
{
}
else
{
callbackIds
.
length
=
0
successCallbackIds
=
[]
}
}
}
}
// 移除实时地理位置变化事件的监听函数
export
function
onLocationChangeError
(
callbackId
)
{
errorCallbackIds
.
push
(
callbackId
)
}
export
function
offLocationChangeError
(
callbackId
)
{
export
function
offLocationChangeError
(
callbackId
)
{
callbackOffErrorIds
.
push
(
callbackId
)
if
(
callbackId
)
{
const
index
=
errorCallbackIds
.
indexOf
(
callbackId
)
if
(
index
>=
0
)
{
errorCallbackIds
.
splice
(
index
,
1
)
}
}
else
{
errorCallbackIds
=
[]
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录