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.index0){
that.seleArea = currentCity = city;
plus.storage.removeItem(‘city’);
plus.storage.setItem(‘city’,city);
that.wite = false;
}else if(e.index=&
mui+hbuilder h5+内置获取当前地理位置以及各种权限 兼容iOS/安卓
最新推荐文章于 2024-03-29 15:48:12 发布