微信小程序显示地图与定位实现
微信小程序显示地图与定位实现,比起用Vue实现要简单得多。下面说一下代码:
1.页面
2.定位
//index.js
//获取应用实例
const app = getApp()
Page({
data: {
longitude:116.4965075,
latitude: 40.006103,
speed:0,
accuracy:0
},
//事件处理函数
bindViewTap: function() {
},
onLoad: function () {
var that=this
wx.showLoading({
title:“定位中”,
mask:true
})
wx.getLocation({
type: ‘gcj02’,
altitude:true,//高精度定位
//定位成功,更新定位结果
success: function (res) {
var latitude = res.latitude
var longitude = res.longitude
var speed = res.speed
var accuracy = res.accuracy
that.setData({
longitude:longitud