<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js" type="text/javascript"></script> <script > wx.config({
debug: false,
appId: '<%=appId%>',
timestamp: '<%=timestamp%>',
nonceStr: '<%=nonceStr%>',
signature: '<%=signature%>',
jsApiList: ['checkJsApi', 'getLocation']
});
wx.ready(function () { wx.checkJsApi({
jsApiList: ['getLocation'], // 需要检测的JS接口列表,所有JS接口列表见附录2,
success: function (res) {
var latitude;
var longitude;
var speed;
var accuracy;
var geocoder = null;
wx.getLocation({
type: 'gcj02',
success: function (res) {
latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
speed = res.speed; // 速度,以米/每秒计
accuracy = res.accuracy; // 位置精度
document.getElementById("jindu").innerHTML = latitude;
document.getElementById("weidu").value = latitude; },
cancel: function (res) {
alert('未能获取地理位置');
}
});
}
});
}); </script>
<input type="text" id="jindu" runat="server" style="width: 1px" /> <input type="text" id="weidu" runat="server" style="width: 1px" />页面显示出来为空没有读取经纬度
</div>
debug: false,
appId: '<%=appId%>',
timestamp: '<%=timestamp%>',
nonceStr: '<%=nonceStr%>',
signature: '<%=signature%>',
jsApiList: ['checkJsApi', 'getLocation']
});
wx.ready(function () { wx.checkJsApi({
jsApiList: ['getLocation'], // 需要检测的JS接口列表,所有JS接口列表见附录2,
success: function (res) {
var latitude;
var longitude;
var speed;
var accuracy;
var geocoder = null;
wx.getLocation({
type: 'gcj02',
success: function (res) {
latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
speed = res.speed; // 速度,以米/每秒计
accuracy = res.accuracy; // 位置精度
document.getElementById("jindu").innerHTML = latitude;
document.getElementById("weidu").value = latitude; },
cancel: function (res) {
alert('未能获取地理位置');
}
});
}
});
}); </script>
<input type="text" id="jindu" runat="server" style="width: 1px" /> <input type="text" id="weidu" runat="server" style="width: 1px" />页面显示出来为空没有读取经纬度
</div>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货