Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
fa37075c
U
uni-app
项目概览
DCloud
/
uni-app
3 个月 前同步成功
通知
725
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fa37075c
编写于
9月 07, 2022
作者:
L
lixu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(h5): 增加更新定位 API
上级
a5e95f2c
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
147 addition
and
6 deletion
+147
-6
lib/apis.js
lib/apis.js
+7
-1
lib/modules.json
lib/modules.json
+8
-2
packages/uni-h5/dist/index.css
packages/uni-h5/dist/index.css
+1
-1
packages/uni-h5/dist/index.umd.min.js
packages/uni-h5/dist/index.umd.min.js
+1
-1
packages/uni-h5/manifest.json
packages/uni-h5/manifest.json
+45
-1
src/platforms/h5/service/api/location/location-change.js
src/platforms/h5/service/api/location/location-change.js
+85
-0
未找到文件。
lib/apis.js
浏览文件 @
fa37075c
...
...
@@ -46,7 +46,13 @@ const location = [
'
getLocation
'
,
'
chooseLocation
'
,
'
openLocation
'
,
'
createMapContext
'
'
createMapContext
'
,
'
onLocationChange
'
,
'
onLocationChangeError
'
,
'
startLocationUpdate
'
,
'
stopLocationUpdate
'
,
'
offLocationChange
'
,
'
offLocationChangeError
'
]
const
media
=
[
...
...
lib/modules.json
浏览文件 @
fa37075c
...
...
@@ -48,7 +48,13 @@
"apiList"
:
{
"uni.getLocation"
:
true
,
"uni.openLocation"
:
true
,
"uni.chooseLocation"
:
true
"uni.chooseLocation"
:
true
,
"uni.onLocationChange"
:
true
,
"uni.onLocationChangeError"
:
true
,
"uni.startLocationUpdate"
:
true
,
"uni.stopLocationUpdate"
:
true
,
"uni.offLocationChange"
:
true
,
"uni.offLocationChangeError"
:
true
}
},
{
"name"
:
"media"
,
...
...
@@ -225,7 +231,7 @@
"apiList"
:
{
"uni.createRewardedVideoAd"
:
true
,
"uni.createFullScreenVideoAd"
:
true
,
"uni.'createInterstitialAd'"
:
true
,
"uni.'createInterstitialAd'"
:
true
,
"uni.'createInteractiveAd'"
:
true
}
}]
packages/uni-h5/dist/index.css
浏览文件 @
fa37075c
此差异已折叠。
点击以展开。
packages/uni-h5/dist/index.umd.min.js
浏览文件 @
fa37075c
此差异已折叠。
点击以展开。
packages/uni-h5/manifest.json
浏览文件 @
fa37075c
...
...
@@ -317,6 +317,30 @@
]
]
],
"onLocationChange"
:
[
"/platforms/h5/service/api/location/location-change.js"
,
[]
],
"onLocationChangeError"
:
[
"/platforms/h5/service/api/location/location-change.js"
,
[]
],
"startLocationUpdate"
:
[
"/platforms/h5/service/api/location/location-change.js"
,
[]
],
"stopLocationUpdate"
:
[
"/platforms/h5/service/api/location/location-change.js"
,
[]
],
"offLocationChange"
:
[
"/platforms/h5/service/api/location/location-change.js"
,
[]
],
"offLocationChangeError"
:
[
"/platforms/h5/service/api/location/location-change.js"
,
[]
],
"chooseImage"
:
[
"/platforms/h5/service/api/media/choose-image.js"
,
[
...
...
@@ -431,6 +455,18 @@
[],
true
],
"getWindowInfo"
:
[
"/platforms/h5/service/api/device/get-window-info.js"
,
[]
],
"getDeviceInfo"
:
[
"/platforms/h5/service/api/device/get-system-info.js"
,
[]
],
"getAppBaseInfo"
:
[
"/platforms/h5/service/api/device/get-system-info.js"
,
[]
],
"canIUse"
:
[
"/core/service/api/base/can-i-use.js"
,
[
...
...
@@ -999,11 +1035,19 @@
]
]
],
"getLaunchOptionsSync"
:
[
"/platforms/h5/service/api/plugin/get-launch-options-sync.js"
,
[]
],
"getEnterOptionsSync"
:
[
"/platforms/h5/service/api/plugin/get-launch-options-sync.js"
,
[]
],
"invokePushCallback"
:
[
"/core/service/api/plugin/push.js"
,
[]
],
"getPushC
i
d"
:
[
"getPushC
lientI
d"
:
[
"/core/service/api/plugin/push.js"
,
[]
],
...
...
src/platforms/h5/service/api/location/location-change.js
0 → 100644
浏览文件 @
fa37075c
const
{
invokeCallbackHandler
:
invoke
}
=
UniServiceJSBridge
const
callbackIds
=
[]
const
callbackOnErrorIds
=
[]
const
callbackOffErrorIds
=
[]
let
watchId
/**
* 开始更新定位
*/
export
function
startLocationUpdate
()
{
if
(
navigator
.
geolocation
)
{
watchId
=
navigator
.
geolocation
.
watchPosition
(
res
=>
{
callbackIds
.
forEach
(
callbackId
=>
{
invoke
(
callbackId
,
res
.
coords
)
})
},
error
=>
{
callbackOnErrorIds
.
forEach
(
callbackId
=>
{
invoke
(
callbackId
,
{
errMsg
:
'
getLocation:fail
'
+
error
.
message
})
})
}
)
}
else
{
callbackOnErrorIds
.
forEach
(
callbackId
=>
{
invoke
(
callbackId
,
{
errMsg
:
'
getLocation:fail device nonsupport geolocation
'
})
})
}
}
/**
* 暂停更新定位
* @param {*} callbackId
*/
export
function
stopLocationUpdate
(
callbackId
)
{
if
(
watchId
)
{
navigator
.
geolocation
.
clearWatch
(
watchId
)
}
else
{
invoke
(
callbackId
,
{
errMsg
:
'
stopLocationUpdate:fail
'
})
}
return
{}
}
/**
* 监听更新定位
* @param {*} callbackId
*/
export
function
onLocationChange
(
callbackId
)
{
callbackIds
.
push
(
callbackId
)
}
/**
* 监听更新定位失败
* @param {*} callbackId
*/
export
function
onLocationChangeError
(
callbackId
)
{
callbackOnErrorIds
.
push
(
callbackId
)
}
// 移除实时地理位置变化事件的监听函数
export
function
offLocationChange
(
callbackId
)
{
if
(
callbackId
)
{
const
index
=
callbackIds
.
indexOf
(
callbackId
)
if
(
index
>=
0
)
{
callbackIds
.
splice
(
index
,
1
)
}
else
{
callbackOffErrorIds
.
forEach
(
callbackId
=>
{
invoke
(
callbackId
,
{
errMsg
:
'
offLocationChange:fail
'
})
})
}
}
else
{
callbackIds
.
length
=
0
}
}
// 移除实时地理位置变化事件的监听函数
export
function
offLocationChangeError
(
callbackId
)
{
callbackOffErrorIds
.
push
(
callbackId
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录