//-----------------定位 Start----------------
mui.plusReady(function() {
var localtitle = document.getElementById("local");
var db_lo = plus.storage.getItem("local")
if (db_lo == null) {
try {
plus.nativeUI.showWaiting("首次登录,正在定位...", {
padlock: false
});
plus.geolocation.getCurrentPosition(function(position) {
var codns = position.coords; //获取地理坐标信息;
var geoc = new BMap.Geocoder();
var pt = new BMap.Point(codns.longitude, codns.latitude);
geoc.getLocation(pt, function(rs) {
var addComp = rs.addressComponents;
var lo = addComp.city + "," + addComp.district + "," + addComp.street + "," + addComp.streetNumber;
localtitle.innerHTML = addComp.district;
plus.storage.setItem("local", addComp.district);
console.log(lo);
plus.nativeUI.closeWaiting();
});
}, function(e) {
alert("获取定位位置信息失败:" + e.message);
plus.nativeUI.closeWaiting();
}, {
provider: 'baidu'
});
} catch (e) {
alert(e.message);
plus.nativeUI.closeWaiting();
}
} else {
localtitle.innerHTML = db_lo;
plus.geolocation.getCurrentPosition(function(position) {
var codns = position.coords; //获取地理坐标信息;
var geoc = new BMap.Geocoder();
var pt = new BMap.Point(codns.longitude, codns.latitude);
geoc.getLocation(pt, function(rs) {
var addComp = rs.addressComponents;
if (addComp.district != db_lo) {
mui.confirm('发现地址变化,当前为:' + addComp.district + '\r\n是否切换?', '位置变更', ['是', '否'], function(e) {
if (e.index == 0) {
plus.storage.setItem("local", addComp.district);
localtitle.innerHTML = addComp.district;
}
})
}
})
});
}
});
//-----------------定位 End----------------
笔迹
- 发布:2015-05-16 00:12
- 更新:2018-12-19 10:04
- 阅读:11405
9 个评论
要回复文章请先登录或注册
5***@qq.com
距离您98米
距离您98米
距离您98米
王老吉
云钦
小云菜
笔迹 (作者)
太阳光