Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
0805d1c0
H
Hello UTS
项目概览
DCloud
/
Hello UTS
通知
1605
Star
27
Fork
9
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
2
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
Hello UTS
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
2
Issue
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
0805d1c0
编写于
11月 22, 2022
作者:
DCloud_iOS_XHY
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
腾讯定位模块增加 监听位置变化,清除监听 方法
上级
84c979e8
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
170 addition
and
83 deletion
+170
-83
pages/SDKIntegration/TencentLocation/TencentLocation.vue
pages/SDKIntegration/TencentLocation/TencentLocation.vue
+98
-68
uni_modules/uts-screenshot-listener/utssdk/app-ios/index.uts
uni_modules/uts-screenshot-listener/utssdk/app-ios/index.uts
+2
-4
uni_modules/uts-tencentgeolocation/utssdk/app-ios/index.uts
uni_modules/uts-tencentgeolocation/utssdk/app-ios/index.uts
+70
-11
未找到文件。
pages/SDKIntegration/TencentLocation/TencentLocation.vue
浏览文件 @
0805d1c0
...
...
@@ -3,23 +3,31 @@
<page-head
:title=
"title"
></page-head>
<view
class=
"uni-padding-wrap uni-common-mt"
>
<view
class=
"uni-hello-text"
>
1. 腾讯定位sdk需在腾讯地图官网申请key。https://lbs.qq.com/mobile/androidMapSDK/
developerGuide/getKey。
1. 腾讯定位sdk需在腾讯地图官网申请key。 https://lbs.qq.com/
</view>
<view
class=
"uni-hello-text"
>
2. 将key配置在uts插件uts-tencentgeolocation/utssdk/app-android/AndroidManifest.xml中。
2. 按照readme文档配置apikey
</view>
<view
class=
"uni-hello-text"
>
3. 需要制作自定义基座运行
</view>
</view>
<view
class=
"uni-btn-v uni-common-mt"
>
<button
type=
"primary"
@
tap=
"checkLocationPermission"
>
请求定位权限
</button>
<button
type=
"primary"
@
tap=
"testGetlocation"
>
腾讯地图获取定位(需自定义基座)
</button>
<button
type=
"primary"
@
tap=
"testGetlocation"
>
获取设备位置信息
</button>
<button
type=
"primary"
@
tap=
"testWatchPosition"
>
监听设备位置信息
</button>
<button
type=
"primary"
@
tap=
"testClearWatch"
>
停止监听
</button>
</view>
</view>
</
template
>
<
script
>
import
{
requestPremission
,
getLocation
}
from
"
@/uni_modules/uts-tencentgeolocation
"
;
import
{
requestPremission
,
getLocation
,
watchPosition
,
clearWatch
}
from
"
@/uni_modules/uts-tencentgeolocation
"
;
export
default
{
data
()
{
...
...
@@ -29,37 +37,59 @@
},
methods
:
{
checkLocationPermission
:
function
(
e
){
checkLocationPermission
:
function
(
e
)
{
requestPremission
();
},
testGetlocation
:
function
(
e
){
testGetlocation
:
function
(
e
)
{
let
startRet
=
getLocation
({
geocode
:
true
,
success
:
function
(
response
){
geocode
:
true
,
success
:
function
(
response
)
{
console
.
log
(
response
);
var
addressDesc
=
response
.
name
+
'
-
'
+
response
.
address
uni
.
showToast
({
title
:
'
执行结果:
'
+
addressDesc
,
icon
:
'
none
'
title
:
'
执行结果:
'
+
addressDesc
,
icon
:
'
none
'
});
},
fail
:
function
(
msg
)
{
fail
:
function
(
msg
)
{
uni
.
showToast
({
title
:
msg
,
icon
:
"
none
"
icon
:
"
none
"
})
}
})
if
(
!
startRet
){
if
(
!
startRet
)
{
uni
.
showToast
({
title
:
'
定位启动失败,请检查配置
'
,
icon
:
'
none
'
title
:
'
定位启动失败,请检查配置
'
,
icon
:
'
none
'
});
}
},
testWatchPosition
()
{
watchPosition
({
geocode
:
true
,
success
:
function
(
response
)
{
console
.
log
(
response
);
var
addressDesc
=
response
.
name
+
'
-
'
+
response
.
address
uni
.
showToast
({
title
:
'
执行结果:
'
+
addressDesc
,
icon
:
'
none
'
});
},
fail
:
function
(
msg
)
{
uni
.
showToast
({
title
:
msg
,
icon
:
"
none
"
})
}
})
},
testClearWatch
()
{
clearWatch
()
}
}
}
</
script
>
...
...
uni_modules/uts-screenshot-listener/utssdk/app-ios/index.uts
浏览文件 @
0805d1c0
...
...
@@ -20,17 +20,15 @@ class CaptureScreenTool {
// 捕获截屏回调的方法
// target-action 的方法前需要添加 @objc 前缀
@objc static userDidTakeScreenshot() {
const obj = new UTSJSONObject()
// 回调
this.listener?.(
obj
)
this.listener?.(
{}
)
}
// 移除监听事件
static removeListen(callback?: UTSCallback) {
this.listener = null
NotificationCenter.default.removeObserver(this)
const obj = new UTSJSONObject()
callback?.(obj)
callback?.({})
}
}
...
...
uni_modules/uts-tencentgeolocation/utssdk/app-ios/index.uts
浏览文件 @
0805d1c0
import { CLLocationManager, CLAuthorizationStatus } from "CoreLocation"
import { TencentLBSLocationManager, TencentLBSLocation, Error, TencentLBSRequestLevel} from "TencentLBS"
import { TencentLBSLocationManager, TencentLBSLocation, Error, TencentLBSRequestLevel
, TencentLBSLocationManagerDelegate
} from "TencentLBS"
import Bundle from "Foundation"
...
...
@@ -25,13 +25,15 @@ type LocationResponse = {
/**
* 定位 LBSLocation 类,封装定位相关方法
*/
class LBSLocation {
class LBSLocation
implements TencentLBSLocationManagerDelegate
{
// 定义 locationManager 属性,类型为 TencentLBSLocationManager
static locationManager: TencentLBSLocationManager
locationManager: TencentLBSLocationManager
locationOptions?: LocationOptions
// 初始化 locationManager 方法
static
configLocationManager(): boolean {
configLocationManager(): boolean {
if (this.locationManager == null) {
// 从 info.plist 中读取 apiKey
...
...
@@ -48,13 +50,14 @@ class LBSLocation {
this.locationManager = new TencentLBSLocationManager()
// 设置 apiKey (因为 apiKey 是 any?类型,需要转成 string 类型赋值)
this.locationManager.apiKey = apiKey! as string;
this.locationManager.delegate = this
}
return true
}
// 请求定位权限
static
requestPremission() {
requestPremission() {
if (this.configLocationManager()) {
const status = CLLocationManager.authorizationStatus()
// 如果未获取过定位权限,则发起权限请求
...
...
@@ -64,8 +67,8 @@ class LBSLocation {
}
}
// 获取位置信息
static
getLocation(locationOptions: LocationOptions): boolean {
// 获取
单次
位置信息
getLocation(locationOptions: LocationOptions): boolean {
// 初始化 locationManager
if (!this.configLocationManager()) {
...
...
@@ -95,18 +98,74 @@ class LBSLocation {
return true
}
// 监听位置变化
watchPosition(locationOptions: LocationOptions) {
// 初始化 locationManager
if (!this.configLocationManager()) {
return
}
if (locationOptions.geocode) {
this.locationManager.requestLevel = TencentLBSRequestLevel.name
} else {
this.locationManager.requestLevel = TencentLBSRequestLevel.geo
}
this.locationOptions = locationOptions
this.locationManager.startUpdatingLocation()
}
// 清除监听
clearWatch() {
// 初始化 locationManager
if (!this.configLocationManager()) {
return
}
this.locationManager.stopUpdatingLocation()
}
// 实现定位出错的 delegate 方法
tencentLBSLocationManager(manager: TencentLBSLocationManager, error: Error) {
this.locationOptions?.fail(error.localizedDescription)
}
// 实现位置更新的 delegate 方法
tencentLBSLocationManager(manager: TencentLBSLocationManager, @argumentLabel("didUpdate") location: TencentLBSLocation) {
let response = new LocationResponse();
response.name = location.name;
response.address = location.address;
response.latitude = Number(location.location.coordinate.latitude);
response.longitude = Number(location.location.coordinate.longitude);
this.locationOptions?.success(response)
}
}
const LBSLocationTool: LBSLocation = new LBSLocation()
/**
*
导出请求
权限方法
*
请求定位
权限方法
*/
export function requestPremission() {
LBSLocation.requestPremission()
LBSLocation
Tool
.requestPremission()
}
/*
*
导出请求位置信息方法
*
获取位置信息方法(单次定位)
*/
export function getLocation(locationOptions: LocationOptions): boolean {
return LBSLocation.getLocation(locationOptions)
return LBSLocationTool.getLocation(locationOptions)
}
/**
* 持续监听位置变化
*/
export function watchPosition(locationOptions: LocationOptions) {
LBSLocationTool.watchPosition(locationOptions)
}
/**
* 关闭监听位置变化
*/
export function clearWatch() {
LBSLocationTool.clearWatch()
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录