当前位置: 首页 > wzjs >正文

泗阳网站定制如何做淘宝商城网站设计

泗阳网站定制,如何做淘宝商城网站设计,网站建设策划包括哪些内容,怎么仿网站一、简介 位置服务提供GNSS定位、网络定位(蜂窝基站、WLAN、蓝牙定位技术)、地理编码、逆地理编码、国家码和地理围栏等基本功能。 使用位置服务时请打开设备“位置”开关。如果“位置”开关关闭并且代码未设置捕获异常,可能导致应用异常。 …

一、简介

位置服务提供GNSS定位、网络定位(蜂窝基站、WLAN、蓝牙定位技术)、地理编码、逆地理编码、国家码和地理围栏等基本功能。

使用位置服务时请打开设备“位置”开关。如果“位置”开关关闭并且代码未设置捕获异常,可能导致应用异常。

二、申请位置权限

2.1 场景概述

应用在使用Location Kit系统能力前,需要检查是否已经获取用户授权访问设备位置信息。如未获得授权,可以向用户申请需要的位置权限。

系统提供的定位权限有:

  • ohos.permission.LOCATION:用于获取精准位置,精准度在米级别。
  • ohos.permission.APPROXIMATELY_LOCATION:用于获取模糊位置,精确度为5公里。
  • ohos.permission.LOCATION_IN_BACKGROUND:用于应用切换到后台仍然需要获取定位信息的场景。
2.2 开发步骤
  1. 开发者可以在应用配置文件中声明所需要的权限并向用户申请授权,具体可参考向用户申请授权。
  2. 当APP运行在前台,且访问设备位置信息时,申请位置权限的方式如下:
申请位置权限的方式是否允许申请申请成功后获取的位置的精确度
申请ohos.permission.APPROXIMATELY_LOCATION获取到模糊位置,精确度为5公里。
同时申请ohos.permission.APPROXIMATELY_LOCATION和ohos.permission.LOCATION获取到精准位置,精准度在米级别。

当APP运行在后台时,申请位置权限的方式如下:
如果应用在后台运行时也需要访问设备位置,除了按照步骤2申请权限外,还需要申请LOCATION类型的长时任务

三、导入模块

import { geoLocationManager } from '@kit.LocationKit';

四、示例

效果图

在这里插入图片描述

示例代码

import { abilityAccessCtrl, bundleManager, common, Permissions } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { geoLocationManager } from '@kit.LocationKit';
import { intl } from '@kit.LocalizationKit';async function checkPermissionGrant(permission: Permissions): Promise<abilityAccessCtrl.GrantStatus> {let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();let grantStatus: abilityAccessCtrl.GrantStatus = abilityAccessCtrl.GrantStatus.PERMISSION_DENIED;// 获取应用程序的accessTokenIDlet tokenId: number = 0;try {let bundleInfo: bundleManager.BundleInfo =await bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION);let appInfo: bundleManager.ApplicationInfo = bundleInfo.appInfo;tokenId = appInfo.accessTokenId;} catch (error) {const err: BusinessError = error as BusinessError;console.error(`获取应用程序的accessTokenID Failed to get bundle info for self. Code is ${err.code}, message is ${err.message}`);}// 校验应用是否被授予权限try {grantStatus = await atManager.checkAccessToken(tokenId, permission);} catch (error) {const err: BusinessError = error as BusinessError;console.error(`校验应用是否被授予权限 Failed to check access token. Code is ${err.code}, message is ${err.message}`);}return grantStatus;
}async function checkPermissions(context: common.UIAbilityContext): Promise<void> {let grantStatus1: boolean = await checkPermissionGrant('ohos.permission.LOCATION') ===abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED; // 获取精确定位权限状态let grantStatus2: boolean = await checkPermissionGrant('ohos.permission.APPROXIMATELY_LOCATION') ===abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED; // 获取模糊定位权限状态// 精确定位权限只能跟模糊定位权限一起申请,或者已经有模糊定位权限才能申请精确定位权限if (grantStatus2 && !grantStatus1) {// 申请精确定位权限reqPermissionsFromUser(permissionsOne, context)} else if (!grantStatus1 && !grantStatus2) {// 申请模糊定位权限与精确定位权限或单独申请模糊定位权限reqPermissionsFromUser(permissionsTow, context)} else {// 已经授权,可以继续访问目标操作getCurrentLocation()}
}const permissionsOne: Array<Permissions> = ['ohos.permission.LOCATION'];const permissionsTow: Array<Permissions> = ['ohos.permission.LOCATION', 'ohos.permission.APPROXIMATELY_LOCATION'];// 使用UIExtensionAbility:将common.UIAbilityContext 替换为common.UIExtensionContext
function reqPermissionsFromUser(permissions: Array<Permissions>, context: common.UIAbilityContext): void {let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();// requestPermissionsFromUser会判断权限的授权状态来决定是否唤起弹窗atManager.requestPermissionsFromUser(context, permissions).then((data) => {let grantStatus: Array<number> = data.authResults;let length: number = grantStatus.length;for (let i = 0; i < length; i++) {if (grantStatus[i] === 0) {// 用户授权,可以继续访问目标操作} else {// 用户拒绝授权,提示用户必须授权才能访问当前页面的功能,并引导用户到系统设置中打开相应的权限return;}}// 授权成功getCurrentLocation()}).catch((err: BusinessError) => {console.error(`Failed to request permissions from user. Code is ${err.code}, message is ${err.message}`);})
}function getCurrentLocation() {// 实例化位置信息请求对象,确认当前定位策略。以实例化SingleLocationRequest对象为例,将其定位方式优先级设置为快速获取位置优先,定位超时时间设置为10秒let request: geoLocationManager.SingleLocationRequest = {locatingPriority: geoLocationManager.LocatingPriority.PRIORITY_LOCATING_SPEED,locatingTimeoutMs: 10000};// 根据定位策略,调用getCurrentLocation()接口获取当前位置信息geoLocationManager.getCurrentLocation(request).then((location: geoLocationManager.Location) => {// Receive the reported location through the promise.const latitude = location.latitude;// 纬度const longitude = location.longitude;// 经度const speed = location.speed;const accuracy = location.accuracy;// 精度const sourceType = location.sourceType;// 定位来源const direction = location.direction;// 表示航向信息。单位是“度”,取值范围为0到360。const timeStamp = location.timeStamp;let dateFormat8 = new intl.DateTimeFormat('zh-CN', {year: 'numeric',month: '2-digit',day: '2-digit',hour: '2-digit',minute: '2-digit',second: '2-digit'})let formattedTimeDate = dateFormat8.format(new Date(timeStamp))formattedTimeDate = formattedTimeDate.replaceAll('/', ".");// 2025.04.03 18:16:08console.log(`formattedTimeDate = ${formattedTimeDate} 获取当前位置信息 latitude = ${latitude} , longitude = ${longitude}, speed = ${speed}, accuracy = ${accuracy} , sourceType = ${sourceType} , direction = ${direction}`);}).catch((err: BusinessError) => {console.log(`获取当前位置信息 getCurrentLocationPosition failed, code: ${err.code}, message: ${err.message}`)});// 调用getAddressesFromLocation()接口进行逆地理编码转化,将位置坐标信息转换为对应的地理位置描述。// geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest, async (err, data) => {//   if (data) {//     this.address = data[0]?.placeName || '';//     // ...//   } else {//     console.log(`将位置坐标信息转换为对应的地理位置描述 getAddressesFromLocation failed, code: ${err.code}, message: ${err.message}`)//   }// });
}@Entry
@Component
struct TestLocation {@State message: string = '当前位置信息';private context = getContext(this) as common.UIAbilityContext;build() {Column({ space: 10 }) {Text(this.message).id('TestLocationMapHelloWorld').fontSize(20).fontWeight(FontWeight.Medium)Button("获取位置信息").fontColor(Color.Black).fontSize(20).onClick(() => {checkPermissions(this.context)})}.height('100%').width('100%').margin({ top: 50 })}
}

文章转载自:

http://OZ3LY9oI.smyxL.cn
http://pjHe5v7G.smyxL.cn
http://7eLvUPGU.smyxL.cn
http://gQBBLu7c.smyxL.cn
http://Hlf14wZa.smyxL.cn
http://jd1kw9SM.smyxL.cn
http://mvUCx62u.smyxL.cn
http://UPaPZrBI.smyxL.cn
http://KxYaJafn.smyxL.cn
http://cWNaoVT5.smyxL.cn
http://1LObhzx3.smyxL.cn
http://VvtGoStz.smyxL.cn
http://0uUPofCm.smyxL.cn
http://dTJ08KUi.smyxL.cn
http://vwbMgduz.smyxL.cn
http://fwdW1L4p.smyxL.cn
http://G8E3juXA.smyxL.cn
http://QeiXV00k.smyxL.cn
http://nyOnxP2v.smyxL.cn
http://zN9DZFXQ.smyxL.cn
http://CVNyvTwA.smyxL.cn
http://tV5cfNVi.smyxL.cn
http://Jtfs0Opf.smyxL.cn
http://8ODmr2iy.smyxL.cn
http://AOtSwx7f.smyxL.cn
http://urU8BKCQ.smyxL.cn
http://K4m1w4BL.smyxL.cn
http://MdCFIye0.smyxL.cn
http://qBV1HkH0.smyxL.cn
http://pc9WznzW.smyxL.cn
http://www.dtcms.com/wzjs/767587.html

相关文章:

  • 官方网站开发与定制公司logo标志设计免费
  • 网站建设柒金手指花总11建设摩托车官方旗舰店
  • 网站规划书市场分析wordpress需要什么配置文件
  • 建设公司网站源码常州便宜的做网站服务
  • 网络文学网站开发如何做服装的微商城网站建设
  • 做网站的费用会计分录做网站需要哪些钱
  • 潍坊网站建设 中公asp+php+mysql+aspx环境搭建与6种网站安装2
  • 自己做视频网站资源从哪里来wordpress修改文章页面模板
  • 网站建设公司广告标题语白银市建设管理处网站
  • 做网站什么主题比较好wordpress 支付宝捐赠
  • 高质量的常州网站建设甘肃省建设信息平台
  • 网站开发工具特点总结域名备案和网站备案有什么区别
  • 重庆智能模板建站东营教育信息网官网
  • 网站建设培训视频建设网站的公司排名
  • 企业网站建设的背景和目的淄博网站公司
  • 张家港电脑网站制作网站开发html文件规范
  • 什么免费网站可以链接域名全网营销公司
  • 行业网站源码河北邢台区号
  • 多仓库版仓库管理网站建设源码it运维
  • 张家港江阴网站制作广州网站建设网站定制
  • 怎么用idea做响应式网站百度小说风云榜今天
  • jq做6个网站做什么好如何利用网络进行推广和宣传
  • 西山区城市建设局网站新网站seo技术
  • 学校网站建设经验介绍淘宝网店代运营哪家好
  • 吕梁做网站的公司网站精简布局
  • 网站推广软文选天天软文seo优化sem
  • 设计师网站介绍wordpress jetpack 3.7.2
  • 网站地图在线制作工具品牌网站制作简创网络
  • 浙江邮电建设工程有限公司网站网站平台建设合同
  • 怎样做网站运营上海加盟网站建设