Hbuider hybrid app开发之地图位置信息操作方法

来源:互联网 发布:大型投资理财网站源码 编辑:程序博客网 时间:2024/06/08 18:21
/** * 位置工具 * */var watchId = null;/** * @description 监听位置变化信息 * */ function watchPosition(){    if (watchId) {        return;    }    watchId = plus.geolocation.watchPosition(function(p){        geoInf(p);        postToServer(p);    }, function(e){        alert("Geolocation error: " + e.message);    }); }/** * @description 通过定位模块获取位置信息 * */ function getGeocode() {    plus.geolocation.getCurrentPosition(geoInf, function(e) {        mui.alert("获取定位位置信息失败:" + e.message);    }, {        geocode: true,        provider: 'amap'    });}/** * @description 上传位置信息 * */ function postToServer(position) {    var str = "";    str += "地址:" + position.addresses + "\n"; //获取地址信息    str += "坐标类型:" + position.coordsType + "\n";    var timeflag = position.timestamp; //获取到地理位置信息的时间戳;一个毫秒数;    str += "时间戳:" + timeflag + "\n";    var codns = position.coords; //获取地理坐标信息;    var lat = codns.latitude; //获取到当前位置的纬度;    str += "纬度:" + lat + "\n";    var longt = codns.longitude; //获取到当前位置的经度    str += "经度:" + longt + "\n";    var alt = codns.altitude; //获取到当前位置的海拔信息;    str += "海拔:" + alt + "\n";    var accu = codns.accuracy; //地理坐标信息精确度信息;    str += "精确度:" + accu + "\n";    var altAcc = codns.altitudeAccuracy; //获取海拔信息的精确度;    str += "海拔精确度:" + altAcc + "\n";    var head = codns.heading; //获取设备的移动方向;    str += "移动方向:" + head + "\n";    var sped = codns.speed; //获取设备的移动速度;    str += "移动速度:" + sped;    console.log(JSON.stringify(position));}/** * @description 处理位置信息 * */ function geoInf(position) {    var str = "";    str += "地址:" + position.addresses + "\n"; //获取地址信息    str += "坐标类型:" + position.coordsType + "\n";    var timeflag = position.timestamp; //获取到地理位置信息的时间戳;一个毫秒数;    str += "时间戳:" + timeflag + "\n";    var codns = position.coords; //获取地理坐标信息;    var lat = codns.latitude; //获取到当前位置的纬度;    str += "纬度:" + lat + "\n";    var longt = codns.longitude; //获取到当前位置的经度    str += "经度:" + longt + "\n";    var alt = codns.altitude; //获取到当前位置的海拔信息;    str += "海拔:" + alt + "\n";    var accu = codns.accuracy; //地理坐标信息精确度信息;    str += "精确度:" + accu + "\n";    var altAcc = codns.altitudeAccuracy; //获取海拔信息的精确度;    str += "海拔精确度:" + altAcc + "\n";    var head = codns.heading; //获取设备的移动方向;    str += "移动方向:" + head + "\n";    var sped = codns.speed; //获取设备的移动速度;    str += "移动速度:" + sped;    console.log(JSON.stringify(position));}/** * @description 停止监听位置变化信息 * */ function clearWatch(){    if (watchId) {        plus.geolocation.clearWatch(watchId);        watchId = null;    }}
0 0
原创粉丝点击