这里有新鲜出炉的微信小程序入门,程序狗速度看过来!
微信小程序(weixinxiaochengxu),简称小程序,缩写 XCX,英文名 mini program,是一种不需要下载安装即可使用的应用,它实现了应用 "触手可及" 的梦想,用户扫一扫或搜一下即可打开应用。
这篇文章主要介绍了微信小程序 获取当前地理位置和经纬度实例代码的相关资料, 这里附有实例代码,及实现效果图,需要的朋友可以参考下
微信小程序实例 - 获取当前的地理位置、经纬度
微信小程序官方文档
https://mp.weixin.qq.com/debug/wxadoc/dev/api/location.html
JS 代码
- //index.js
- //获取应用实例
- var app = getApp() Page({
- data: {
- motto: '示例小程序-获取当前地理位、速度',
- userInfo: {},
- hasLocation: false,
- location: {}
- },
- //事件处理函数
- bindViewTap: function() {
- wx.navigateTo({
- url: '../logs/logs'
- })
- },
- onLoad: function() {
- console.log('onLoad') var that = this
- //调用应用实例的方法获取全局数据
- app.getUserInfo(function(userInfo) {
- //更新数据
- that.setData({
- userInfo: userInfo
- })
- }),
- wx.getLocation({
- success: function(res) {
- console.log(res) that.setData({
- hasLocation: true,
- location: {
- longitude: res.longitude,
- latitude: res.latitude
- }
- })
- }
- })
- }
- })
index.wxml
- <!--index.wxml-->
- <view class="container">
- <view bindtap="bindViewTap" class="userinfo">
- <image class="userinfo-avatar" src="{{userInfo.avatarUrl}}" background-size="cover">
- </image>
- <text class="userinfo-nickname">
- {{userInfo.nickName}}
- </text>
- </view>
- <view class="usermotto">
- <!-- <text class="user-motto">{{motto}}\n</text>-->
- <text>
- 经度:{{location.longitude}}\n
- </text>
- <text>
- 纬度:{{location.latitude}}
- </text>
- </view>
- </view>
运行效果
来源: http://www.phperz.com/article/17/0718/329865.html