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

浙江网站建设流程wordpress搬迁后多媒体库无法

浙江网站建设流程,wordpress搬迁后多媒体库无法,济南建网站公司,李嘉诚预言2025房价走势前言 地图定位功能相信很多人都用过,在鸿蒙的应用程序开发中,使用高德地图的定位功能变得十分常见,那么在鸿蒙中一次完整的地位功能怎么实现?如果定位失败了,能否获取前几次的定位呢?本篇文章带你实现一个…

前言

地图定位功能相信很多人都用过,在鸿蒙的应用程序开发中,使用高德地图的定位功能变得十分常见,那么在鸿蒙中一次完整的地位功能怎么实现?如果定位失败了,能否获取前几次的定位呢?本篇文章带你实现一个完整的定位功能流程,建议点赞收藏!

需求分析

要想实现一个完整的定位需求流程,就必须要做好准备工作,了解实现需求的具体步骤。

  • 权限申请
  • 检查 GPS 是否打开
  • 单次定位还是多次定位
  • 定位失败处理

技术实现

要想实现一次完整的定位流程,必须根据需要分析一步步去实现,由于高德地图的引入太过于简单,这里一笔带过。重点讲解完整实现的步骤。

  1. 添加基本定位权限,在 entry 模块下的 module.json5 中添加定位必要的两个权限。
 {// user_grant"name": "ohos.permission.APPROXIMATELY_LOCATION","reason": "$string:location_permissions_reason","usedScene": {"abilities": ["EntryAbility"],"when": "always"}},{// user_grant"name": "ohos.permission.LOCATION","reason": "$string:location_permissions_reason","usedScene": {"abilities": ["EntryAbility"],"when": "always"}},
  1. 在页面中进行权限申请,一般是在 onPageShow 生命周期方法中申请,先检查系统 GPS 定位开关是否开启,如果没有开启则提示用户跳转到系统指定位置打开。
 let location =  geoLocationManager.isLocationEnabled()if (!location) {let dialog = new OpenSystemGPSEHelper()dialog.show(this.getUIContext(),getContext(this) as common.UIAbilityContext,()=>{this.currentCity = "定位失败"})}//GPS跳转页面
context.startAbility({bundleName: "com.huawei.hmos.settings",abilityName: "com.huawei.hmos.settings.MainAbility",uri: "location_manager_settings"},
  1. 确认 GPS 打开之后,开始 申请 用户权限。
 static applyPermission(context: common.UIAbilityContext, permissions: Array<Permissions>, grantedBlock: () => void,deniedBlock?: () => void) {let atManager = abilityAccessCtrl.createAtManager()let permissionGrantedNumber: number = 0 atManager.requestPermissionsFromUser(context, permissions).then((data) => {for (let index = 0; index < data.authResults.length; index++) {if (data.authResults[index] == 0) { permissionGrantedNumber++;}}if (permissionGrantedNumber == permissions.length) {grantedBlock()} else {if (deniedBlock) {deniedBlock()} else {PermissionUtil.openPermissionsInSystemSettings(context)}}})}
  1. 如果用户打开权限,则直接开始定位服务,否则提示用户跳转到系统指定位置打开权限。
 let wantInfo: Want = {bundleName: 'com.huawei.hmos.settings',abilityName: 'com.huawei.hmos.settings.MainAbility',uri: 'application_info_entry',parameters: {settingsParamBundleName: bundleInfo.name}}context.startAbility(wantInfo).then(() => {})
  1. 确认定位权限没问题后,开始定位,高德提供的定位有多次和单次,这里使用单次定位。
let listener: IAMapLocationListener = {onLocationChanged: (location) => {console.log("当前定位1:"+location.latitude+",---longitude:"+location.longitude)this.transformCity(location.latitude,location.longitude)}, onLocationError: (error) => {}};LocationManager.getInstance().addListener(listener)LocationManager.getInstance().initLocation()// 定位参数配置let options: AMapLocationOption = {//定位优先配置选项priority: geoLocationManager.LocationRequestPriority.FIRST_FIX,//定位场景设置scenario: geoLocationManager.LocationRequestScenario.UNSET,//定位精度 单位:米maxAccuracy: 0,//指定单次定位超时时间singleLocationTimeout: 3000,//定位是否返回逆地理信息locatingWithReGeocode: true,//逆地址语言类型reGeocodeLanguage: AMapLocationReGeocodeLanguage.Chinese,isOffset: false //是否加偏}// 设置配置this.locationManger?.setLocationOption(AMapLocationType.Single, options)if (this.listener != undefined) {// 监听this.locationManger?.setLocationListener(AMapLocationType.Single, this.listener)}// 启动定位this.locationManger?.requestSingleLocation()
  1. 定位成功拿到定位的信息,在实际开发中尽管设置中已经设置返回逆地理信息,但并没有返回具体信息,这点实在是无法理解,只能得到当前位置的经纬度。这个时候需要将经纬度转换为当前位置名称。
  2. 在开发中通过使用华为官方系统中的 api,对经纬度进行逆编码才能获取准备的位置名称。
 let reverseGeocodeRequest:geoLocationManager.ReverseGeoCodeRequest = {"latitude":latitude, "longitude":longitude, "maxItems": 1};try {geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => {})
  1. 如果地图定位失败,则可以根据高德地图提供的方法,尝试拿取历史定位信息。
 LocationManager.getInstance().getLastLocation({onLocationChanged: (location) => {console.info('地图定位缓存获取成功:  ' + JSON.stringify(location))if (success) {success()}}, onLocationError: (e) => {console.info('地图定位缓存获取失败:  ' + JSON.stringify(e))if (success) {success()}}})
  1. 如果历史定位信息也获取失败,这时就能使用默认定位位置了。
     

总结

定位功能实现起来比较简单,但是完整的定位流程及细节处理才是本篇文章的关键,相信看完本篇文章你已经学会在鸿蒙中怎么使用高德定位功能了,快去动手尝试一下吧!


文章转载自:

http://L8UnEUT0.gbxxh.cn
http://GkQc6aZZ.gbxxh.cn
http://dNZMFzlg.gbxxh.cn
http://P1p8s1Hv.gbxxh.cn
http://Lq53bK8R.gbxxh.cn
http://wQDyahVm.gbxxh.cn
http://0JcmmZxE.gbxxh.cn
http://yMMh6VEn.gbxxh.cn
http://BmFmSdzW.gbxxh.cn
http://p0V9ZL7e.gbxxh.cn
http://Tm7rGWeU.gbxxh.cn
http://A4HqcF80.gbxxh.cn
http://b0s6ZlxS.gbxxh.cn
http://tUSr31mN.gbxxh.cn
http://EmgjTJhZ.gbxxh.cn
http://fct2ODij.gbxxh.cn
http://3xeedguk.gbxxh.cn
http://XXAXRQkB.gbxxh.cn
http://W9ho5PL9.gbxxh.cn
http://tE5MRECn.gbxxh.cn
http://CvshoGSH.gbxxh.cn
http://5TEvTnhR.gbxxh.cn
http://YhTsueXn.gbxxh.cn
http://5yl118OY.gbxxh.cn
http://N1vm5z1a.gbxxh.cn
http://cdhBD75Z.gbxxh.cn
http://fdDiIzCF.gbxxh.cn
http://igRLTQdQ.gbxxh.cn
http://cEAJOT5m.gbxxh.cn
http://JiuXVwmP.gbxxh.cn
http://www.dtcms.com/wzjs/772768.html

相关文章:

  • 临泉建设网站中企动力服务怎么样
  • 网站怎么做运营推广正品海外购网站有哪些
  • 做app模板下载网站个人网站 前置审批
  • 计算机编程与网站建设百度手机版网页
  • 海南建设银行官网招聘网站中国建筑企业网
  • 怎样在工商局网站做申请登记产品软文范例
  • 做电影网站的图片素材找人制作网站 优帮云
  • 网站开发费是无形资产吗泉州制作网站设计
  • 苏州网站开发公司电话成都展厅设计公司
  • 织梦网站栏目建设哪家公司做推广优化好
  • wordpress the_title() 字数泉州seo托管
  • 电子商务网站运营与...做海报的软件
  • 网站集约化建设存在的困难漳州北京网站建设公司哪家好
  • 企业网站建设多少钱建设信用卡个人网站
  • 河南做网站公司哪家专业织梦手机网站模板下载
  • 怎么让人理解网站建设软件开发项目流程
  • 外贸 企业网站 建设页面开发
  • 搭建网站 优帮云安康市网站开发
  • 建设管理网站电子商务中网站建设
  • 温州大型网站建设济南正规做网站公司
  • 网站标签怎么做跳转杭州网络公司排名
  • 建设银行网站建设情况编辑wordpress文章页
  • flash网站建设教程网站建设技术人员工作
  • 广州网站外包济宁网站建设 果壳科技
  • 高端企业网站建设服务商shopify
  • 网站布局域名续费一般多少一年
  • 深圳h5响应式网站建设wordpress默认编辑器功能增强
  • 网站平台需要做无形资产吗 怎么做网站怎么维护更新
  • 网站建设要用H5的缺点我自己做的网站打开很慢
  • 宜昌小学网站建设新的南宁网站建设公司