怎么能实现用户定位功能?
发布于 5 年前 作者 leicheng 4008 次浏览 来自 问答

小程序中实现:用户在小程序中定位到他当前所在的具体位置,怎么实现?

有实现的大侠,请提供解决方案,可能其它也有需要的人,一起来讨论吧。我的代码在下面,wx.getLocation,不能实现需求。

//location.js

var app = getApp()

Page( {

data: {

point:{

latitude: 28.454863,

longitude: 117.943433

},

markers: []

},

onLoad: function() {

console.log( ‘地图定位接口getLocation还不能正常获取用户位置!’ )

var that = this;

wx.getLocation( {

type: ‘wgs84’,

success: function( res ) {

var latitude = res.latitude

var longitude = res.longitude

var speed = res.speed

var accuracy = res.accuracy;

var point={

latitude: latitude,

longitude: longitude

}

var markers = [ {

latitude: latitude,

longitude: longitude,

name: ‘地图定位’,

desc: ‘我现在的位置’

}];

that.setData( markers );

that.setData( point );

wx.openLocation({

latitude: res.latitude, // 纬度,范围为-90~90,负数表示南纬

longitude: res.longitude, // 经度,范围为-180~180,负数表示西经

scale: 28, // 缩放比例          

})

}

})

}

})

回到顶部