您当前的位置:首页 > 知识百科 

微信小程序如何实现定位功能?

时间:2023-07-01 14:05 阅读数:7人阅读

  微信小程序如何实现定位功能?微信最近推出了微信小程序功能,很多微信用户问我微信小程序如何实现定位功能?下面小编就带你了解一下微信小程序如何实现定位功能?

  微信小程序实现简单定位功能,简单易读,获取经纬度信息

  在pages下创建一个单页如local

  local.js如下

  var app = getApp()

  Page({

  data:{

  latitude:'',

  longitude:''

  },

  getLocation:function(e) {

  console.log(e)

  var that = this

  wx.getLocation({

  type: 'wgs84', // 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标

  success: function(res){

  console.log(res)

  that.setData({

  longitude:res.longitude,

  latitude:res.latitude

  })

  }

  })

  }

  })

  local.wxml如下

  

  

  经度:

  

  value="{{longitude}}" name="longitude">

  纬度:

  

  value="{{latitude}}" name="latitude">