3,143
社区成员
发帖
与我相关
我的任务
分享
var gps = new array();
function getLocation() {
wx.getLocation({
success: function (res) {
var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
var speed = res.speed; // 速度,以米/每秒计
var accuracy = res.accuracy; // 位置精度
gps.push({'lat':latitude, 'lng':longtitude});
//alert('xx');
},
fail:function(){
gps.push('error')
}
});
}
setInterval("getLocation()", 15000);
怎么通过点击菜单跳转到网页弹出是否获取用户地理位置,点击是后获取用户地理位置。
这个接口是异步的 显然是不能这么调用var gps = new array(); function getLocation() { wx.getLocation({ success: function (res) { var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90 var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。 var speed = res.speed; // 速度,以米/每秒计 var accuracy = res.accuracy; // 位置精度 gps.push({'lat':latitude, 'lng':longtitude}); setTimeout('function(){ getLocation(); }',15000); //alert('xx'); }, fail:function(){ gps.push('error') } }); }
var gps = new array();
function getLocation() {
wx.getLocation({
success: function (res) {
var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
var speed = res.speed; // 速度,以米/每秒计
var accuracy = res.accuracy; // 位置精度
gps.push({'lat':latitude, 'lng':longtitude});
setTimeout('function(){ getLocation(); }',15000);
//alert('xx');
},
fail:function(){
gps.push('error')
}
});
}