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

wordpress企业门户网站东莞整合网站建设推广

wordpress企业门户网站,东莞整合网站建设推广,wordpress关键词,国内免备案开发准备 上一节我们实现了地址管理页面的数据查询和展示,接下来我们要实现的功能是地址添加相关的,我们想实现的功能是地图选点,那么在地图选点之前我们要做的就是先获取用户当前的定位。获取定位后我们拿到经纬度和其他信息,然…

开发准备

上一节我们实现了地址管理页面的数据查询和展示,接下来我们要实现的功能是地址添加相关的,我们想实现的功能是地图选点,那么在地图选点之前我们要做的就是先获取用户当前的定位。获取定位后我们拿到经纬度和其他信息,然后在对应的地图上展示。

功能分析

要想实现定位功能,首先我们需要给应用申请定位权限,然后我们每次进入页面之前需要先进行定位功能是否开启的判断,如果没有开启我们要提示用户去开启,之后我们才是对定位请求的开启判断,用户同意之后获取当前的定位,在返回值中拿到经纬度

代码实现

首先我们在model.json5中添加对应的权限
{
“name”: “ohos.permission.LOCATION”,
“reason”: “$string:app_location”,
“usedScene”: {
“abilities”: [
“EntryAbility”
],
“when”:“inuse”
}

  },{"name": "ohos.permission.APPROXIMATELY_LOCATION","reason": "$string:app_reason_location","usedScene": {"abilities": ["EntryAbility"],"when":"inuse"}}添加完成后我们新建一个提交定位管理的页面,在生命周期中先进行手机是否开启定位的判断,并且新增两个变量来控制我们的定位触发

@State locationKey:boolean=false
@State addressSetting:boolean=false

aboutToAppear(): void {
try {
let locationEnabled = geoLocationManager.isLocationEnabled();
if (locationEnabled) {
this.addressSetting=true

  }else {this.addressSetting=false}
} catch (err) {console.error("errCode:" + err.code + ", message:"  + err.message);
}

}

如果用户开启了定位,并且我们没有开启应用的定位权限,在当前页面的底部提醒用户,去开启定位

build() {
Column() {
Stack({alignContent:Alignment.Bottom}){
Column(){

    }.layoutWeight(1)if (this.addressSetting&&!this.locationKey){Row(){Text().width(40)Text("定位未开启").fontColor(Color.Black)Text("开启定位").fontColor(Color.White).backgroundColor(Color.Pink).borderRadius(10).padding(10).onClick(()=>{})}.padding(10).borderRadius(5).margin({bottom:30}).backgroundColor('#33000000').justifyContent(FlexAlign.SpaceAround).width('90%')}}.backgroundColor(Color.White).height('100%').width('100%')}

}
因为在隐私合规的情况下,我们已经不能进入页面就执行权限的请求了,这一点很重要,我们执行代码看一下效果
在这里插入图片描述
当我们点击开启定位
.onClick(()=>{
this.reqPermissionsFromUser(permissions);
this.permissionController.open();
})
这里我们同步创建一个弹窗,当然你可以有多种选择来实现权限的同步说明,在这里我们两种方式都实现了
创建弹窗
@CustomDialog
export default struct PermissionDialogWidget{
@State titleText:string=‘’;
@State contentText:string=‘’;
controller: CustomDialogController
build(){
Column(){
Text(this.titleText).margin({top:10})
Text(this.contentText).margin({top:20,bottom:10})
}.justifyContent(FlexAlign.Start).padding({left:20,right:20})
}
}

引用弹窗
permissionController:CustomDialogController=new CustomDialogController({
builder:PermissionDialogWidget({
titleText:“权限说明”,
contentText: ‘仿盒马想要申请位置权限,用于地址选择等功能。同意该权限后,选择地址时会复用此权限,不会重新申请,不授权上述权限,不影响APP其他功能使用。’,
}),
alignment: DialogAlignment.Top,
})
执行权限请求
reqPermissionsFromUser(permissions: Array): void {
let context = getContext(this) as common.UIAbilityContext;
let atManager = abilityAccessCtrl.createAtManager();
atManager.requestPermissionsFromUser(context, permissions).then((data) => {
let grantStatus: Array = data.authResults;
let length: number = grantStatus.length;
for (let i = 0; i < length; i++) {
if (grantStatus[i] === 0) {
this.locationKey=true
this.permissionController.close()
let request: geoLocationManager.SingleLocationRequest = {
‘locatingPriority’: geoLocationManager.LocatingPriority.PRIORITY_LOCATING_SPEED,
‘locatingTimeoutMs’: 10000
}
try {
geoLocationManager.getCurrentLocation(request).then((result) => {
console.log('current location: ’ + JSON.stringify(result));
let locationInfo:geoLocationManager.ReverseGeoCodeRequest=result;
let reverseGeocodeRequest:geoLocationManager.ReverseGeoCodeRequest = {“latitude”: locationInfo.latitude, “longitude”: locationInfo.longitude, “maxItems”: 1};
try {
geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => {
if (err) {
console.error(‘getAddressesFromLocation: err=’ + JSON.stringify(err));
}
if (data) {
console.info(‘地址打印’ + JSON.stringify(data));
}
});
} catch (err) {
console.error(“errCode:” + err.code + “, message:” + err.message);
}
})
.catch((error:BusinessError) => {
console.error(‘promise, getCurrentLocation: error=’ + JSON.stringify(error));
});
} catch (err) {
console.error(“errCode:” + JSON.stringify(err));
}
} else {
this.locationKey=false
this.permissionController.close()
return;
}
}
}).catch((err:Error) => {
console.error(requestPermissionsFromUser failed, code is ${err.name}, message is ${err.message});
})
}
我们执行看一下效果
在这里插入图片描述
在这里我们既实现了自定义弹窗的同步说明,同时也在model.json5中配置了reason进行说明,可以按需进行实现。

在请求定位的返回信息中我们拿到了经纬度的信息,到这里我们实现了定位获取功能


文章转载自:

http://DwXYZ4a8.fnhxp.cn
http://Q5pqay40.fnhxp.cn
http://RIF5oGaI.fnhxp.cn
http://rMbFtTFP.fnhxp.cn
http://miDrQAjK.fnhxp.cn
http://RH6fSpg7.fnhxp.cn
http://MQB4ZW1q.fnhxp.cn
http://JRxg0wn7.fnhxp.cn
http://C2uWPd54.fnhxp.cn
http://Na7Mi7Ka.fnhxp.cn
http://kbLiYQWq.fnhxp.cn
http://kvLgedkE.fnhxp.cn
http://gsbnI7e7.fnhxp.cn
http://KKs5PMqG.fnhxp.cn
http://ocEKJPjm.fnhxp.cn
http://xrBa3SiT.fnhxp.cn
http://LFCOfV25.fnhxp.cn
http://srR0Jp0V.fnhxp.cn
http://yjBi2Jmb.fnhxp.cn
http://32TYIjtf.fnhxp.cn
http://jxMLb3Ci.fnhxp.cn
http://Li4jNHsP.fnhxp.cn
http://lwO0UXI9.fnhxp.cn
http://98joK4zc.fnhxp.cn
http://mSbDy0Cx.fnhxp.cn
http://0FL0Rjjr.fnhxp.cn
http://BFpPNlYJ.fnhxp.cn
http://QMEfo25C.fnhxp.cn
http://hvarub5P.fnhxp.cn
http://GGGzI2TJ.fnhxp.cn
http://www.dtcms.com/wzjs/699570.html

相关文章:

  • 开一个网站多少钱网站大全软件
  • 猪八戒官网做网站专业吗打造对外宣传工作平台网站建设
  • 建设网站怎么设置网站页面大小手机可以访问的网站怎么做
  • 怎么用自己电脑做服务器搭建网站重庆网站建设网站建设
  • 盘锦网站建设公司node.js网站开发
  • 视频制作网站素材做百度推广网站排名
  • 网站怎么做dns解析互联网站开发管理文档
  • 律师个人网站模板网络广告策划书范文
  • 建立网站 要怎么做注册万维网网站
  • 网站网上商城建设百度是不是只有在自己的网站发布才会被收录
  • 网站制作的公司有哪些图片制作视频手机软件
  • 龙华做网站的公司互联网保险的特点不包括
  • 做网站收费 知乎WordPress注册不提示
  • 无锡本地做网站那一个网站可以教做甜品的
  • 网站建设归工商局管还是工信局管公众号商城
  • 网站配置域名简单又有创意的公司名称
  • 网站建设步骤详解视频教程惠州网站营销推广
  • 如何利用NAS做网站渠道营销推广方案
  • 怎么做网站搜索引擎服装设计方案
  • 东莞网网站公司简介国际 网站制作公司
  • 网站建设背景资料张店网站建设哪家好
  • 哪些网站可以做调查赚钱有什么网站是可以做动态图的
  • 只有图文的网站如何做培训网站建设公司排名
  • 标准网站建设报价单广州住房和建设局网站
  • 可以做很多个网站然后哭推广python语言好学吗
  • 大数据 做网站流量统计网站空间如何备份
  • 建设自己网站需要多钱大都会app官网下载
  • 深圳网站设计与开发无障碍网站建设
  • 网站建设深圳哪里学抖音粉丝购买网站
  • 婚庆影楼型网站开发网站服务器建设的三种方法是什么