我用手机测试在本地的Tomcat服务器上运行正常,address获取位置正确、经纬度也正确;但是我在项目的测试系统上(服务器)不能获取到address,且获取的经纬度室友偏差的。
代码如下:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>地理位置</title>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<link rel="stylesheet" type="text/css" href="../../../css/mui.min.css" />
<link rel="stylesheet" href="../../../css/details.css" />
<link href="../../../css/mui.picker.css" rel="stylesheet" />
<link href="../../../css/mui.poppicker.css" rel="stylesheet" />
<link rel="stylesheet" href="../../../css/mui.picker.min.css" />
<link href="../../../css/mui.min.css" rel="stylesheet" />
<script src="../../../js/mui.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="../../../js/mui.picker.js"></script>
<script type="text/javascript" src="../../../js/mui.poppicker.js"></script>
<script type="text/javascript" src="../../../js/mui.picker.min.js" ></script>
<script src="../../../js/common.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.5&ak=4SDnNAyuCBGBhaB4GuUWFnKfwRqZ84V5"></script>
<script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>
<style type="text/css">
<script type="text/javascript" >
// 扩展API加载完毕后调用onPlusReady回调函数
document.addEventListener('plusready', onPlusReady, false);
// 扩展API加载完毕,现在可以正常调用扩展API
var log;
var lat;
function geoInf( position ) {
var str = "";
str += "地址:"+position.addresses+"\n";//获取地址信息
str += "坐标类型:"+position.coordsType+"\n";
var codns = position.coords;//获取地理坐标信息;
var lati = 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));
alert(1);
alert(position.addresses);
//alert(longt+"--"+lat);
log = longt;
lat = lati;
}
function onPlusReady(){
plus.geolocation.getCurrentPosition( geoInf, function(e){
console.log('Gelocation Error: code - ' + e.code + '; message - ' + e.message);
alert('Gelocation Error: code - ' + e.code + '; message - ' + e.message);
switch(e.code) {
case e.PERMISSION_DENIED:
mui.alert('访问权限被拒绝系统不允许程序获取定位功能');
break;
case e.POSITION_UNAVAILABLE:
mui.alert('位置信息不可用 无法获取有效的位置信息');
break;
case e.TIMEOUT:
mui.alert('获取位置信息超时无法在指定的时间内获取位置信息');
break;
case e.UNKNOWN_ERROR:
mui.alert('未知错误 其它未知错误导致无法获取位置信息');
break;
default : mui.alert("未知错误!");
}
},{geocode:true,provider:'amap'});
//地址
mui('.operate').on('tap', '#getaddress', function() {
mui.ajax(getBaseUrl() + '/order/waipinpai/getlocation',{
type : 'POST',
dateType : 'json',
data :{
log : log,
lat : lat,
},
success: function(result){
if(result.success){
alert(JSON.stringify(result.obj));
}else{
mui.toast(result.msg);
}
},
error: function(xhr,type,errorThrown) {
toastAjaxError(mui,xhr,type,errorThrown);
}
});
});
}
</script>
</head>
<body>
<header class="mui-bar mui-bar-nav">
<button type="button" class="mui-left mui-action-back mui-btn mui-btn-link mui-btn-nav mui-pull-left" style="color: #fff;">
<span class="mui-icon mui-icon-left-nav"></span>返回
</button>
<h1 class="mui-title">位置测试</h1>
</header>
<nav class="mui-bar mui-bar-tab operate" style="background-color: white;">
<a id="getaddress" class="mui-tab-item" style="color: #00aead;">
<span class="mui-icon"><i class="iconfont"></i></span>
<span class="mui-tab-label">地址</span>
</a>
</nav>
<div class="mui-scroll-wrapper mui-content">
<div class="mui-scroll">
<div class="biaoti"></div>
<form class="mui-input-group" id="form1">
<div class="mui-input-row duohang">
<label>地址d</label><textarea id="address" rows="2" ></textarea>
</div>
</form>
</div>
</div>
</body>
</html>
1 个回复
h***@139.com
非常好