mui+hbuilder h5+内置获取当前地理位置以及各种权限 兼容iOS/安卓

document.addEventListener(‘plusready’,function(){
var map = new plus.maps.Map(“map”);
map.getUserLocation(function(state, pos) {
if(0 == state) {
plus.maps.Map.reverseGeocode(pos, {}, function(event) {
var address = event.address; // 转换后的地理位置
var proExp = ‘.+[省]’, cityExp = ‘(.+[市]|香港|澳门|台湾)’, disExp = ‘.+[市|区|县]’;
var province = String(address.match(proExp)); // 省
var city = String(address.match(cityExp)[0]).replace(province,’’); // 市
var area = String(address.match(disExp)[0]).replace(province,’’).replace(city,’’);
if(city.indexOf(‘市’)!=-1){
city = city.substring(0,city.indexOf(‘市’));
}
if(area.indexOf(‘县’)!=-1){
city = area;
}
that.cut = city;
var flag = (plus.storage.getItem(‘city’)!=null)?(plus.storage.getItem(‘city’).indexOf(‘市’)!=-1?plus.storage.getItem(‘city’).slice(0,plus.storage.getItem(‘city’).length-1):plus.storage.getItem(‘city’)):city;
that.flag4 = (plus.storage.getItem(‘city’)!=null)?(plus.storage.getItem(‘city’).indexOf(‘市’)!=-1?plus.storage.getItem(‘city’).slice(0,plus.storage.getItem(‘city’).length-1):plus.storage.getItem(‘city’)):city;
if(flagcity){
plus.storage.setItem(‘city’,flag)
that.seleArea = currentCity = flag;
}else{
mui.confirm(‘当前城市为【’+city+’】是否切换?’,[‘取消’,‘确认’],function (e) {
if(e.index
0){
that.seleArea = currentCity = city;
plus.storage.removeItem(‘city’);
plus.storage.setItem(‘city’,city);
that.wite = false;
}else if(e.index=&

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值