forked from giscafer/wechat-weapp-mapdemo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
laohoubin
committed
Sep 23, 2016
1 parent
cc98842
commit 1bfdc71
Showing
34 changed files
with
294 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
# wechat-weapp-mapdemo | ||
|
||
微信小程序开发demo-地图定位 | ||
|
||
|
||
### Screenshot | ||
|
||
![](./image/screenshot1.png) | ||
|
||
![](./image/screenshot1.png) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//app.js | ||
App({ | ||
onLaunch: function () { | ||
//调用API从本地缓存中获取数据 | ||
var logs = wx.getStorageSync('logs') || [] | ||
logs.unshift(Date.now()) | ||
wx.setStorageSync('logs', logs) | ||
}, | ||
getUserInfo:function(cb){ | ||
var that = this; | ||
if(this.globalData.userInfo){ | ||
typeof cb == "function" && cb(this.globalData.userInfo) | ||
}else{ | ||
//调用登录接口 | ||
wx.login({ | ||
success: function () { | ||
wx.getUserInfo({ | ||
success: function (res) { | ||
that.globalData.userInfo = res.userInfo; | ||
typeof cb == "function" && cb(that.globalData.userInfo) | ||
} | ||
}) | ||
} | ||
}); | ||
} | ||
}, | ||
globalData:{ | ||
userInfo:null | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"pages":[ | ||
"pages/index/index", | ||
"pages/location/location", | ||
"pages/logs/logs" | ||
], | ||
"tabBar": { | ||
"color": "#dddddd", | ||
"selectedColor": "#3cc51f", | ||
"borderStyle": "black", | ||
"backgroundColor": "#ffffff", | ||
"list": [{ | ||
"pagePath": "pages/index/index", | ||
"iconPath": "image/wechat.png", | ||
"selectedIconPath": "image/wechatHL.png", | ||
"text": "首页" | ||
}, { | ||
"pagePath": "pages/location/location", | ||
"iconPath": "image/locate.png", | ||
"selectedIconPath": "image/locateHL.png", | ||
"text": "定位" | ||
},{ | ||
"pagePath": "pages/logs/logs", | ||
"iconPath": "image/wechat.png", | ||
"selectedIconPath": "image/wechat.png", | ||
"text": "日志" | ||
}] | ||
}, | ||
"window":{ | ||
"backgroundTextStyle":"light", | ||
"navigationBarBackgroundColor": "#fff", | ||
"navigationBarTitleText": "Map", | ||
"navigationBarTextStyle":"black" | ||
}, | ||
"debug": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/**app.wxss**/ | ||
.container { | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: space-between; | ||
padding: 200rpx 0; | ||
box-sizing: border-box; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//index.js | ||
//获取应用实例 | ||
var app = getApp() | ||
Page({ | ||
data: { | ||
motto: '微信小程序尝鲜,地图定位', | ||
userInfo: {}, | ||
appInfo:{ | ||
logoUrl:'../../image/wechat.png', | ||
title:'使用微信内置地图查看API定位' | ||
} | ||
}, | ||
//事件处理函数 | ||
bindViewTap: function() { | ||
wx.navigateTo({ | ||
url: '../location/location' | ||
}) | ||
}, | ||
onLoad: function () { | ||
console.log('onLoad') | ||
var that = this | ||
console.log(this.data) | ||
that.setData({ | ||
appInfo:this.data.appInfo | ||
}) | ||
//调用应用实例的方法获取全局数据 | ||
// app.getUserInfo(function(userInfo){ | ||
// //更新数据 | ||
// that.setData({ | ||
// userInfo:userInfo | ||
// }) | ||
// that.update() | ||
// }) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!--index.wxml--> | ||
<view class="container"> | ||
<view bindtap="bindViewTap" class="userinfo"> | ||
<image class="userinfo-avatar" src="{{appInfo.logoUrl}}" background-size="cover"></image> | ||
<text class="userinfo-nickname">{{appInfo.title}}</text> | ||
</view> | ||
<view class="usermotto"> | ||
<text class="user-motto">{{motto}}</text> | ||
</view> | ||
</view> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/**index.wxss**/ | ||
.userinfo { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
|
||
.userinfo-avatar { | ||
width: 128rpx; | ||
height: 128rpx; | ||
margin: 20rpx; | ||
border-radius: 50%; | ||
} | ||
|
||
.userinfo-nickname { | ||
color: #aaa; | ||
} | ||
|
||
.usermotto { | ||
margin-top: 200px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//location.js | ||
//获取应用实例 | ||
var app = getApp() | ||
Page({ | ||
onLoad: function () { | ||
console.log('地图定位!') | ||
var that = this | ||
wx.getLocation({ | ||
type: 'gcj02', //返回可以用于wx.openLocation的经纬度 | ||
success: function (res) { | ||
var latitude = res.latitude; | ||
var longitude = res.longitude; | ||
wx.openLocation({ | ||
latitude:latitude, | ||
longitude:longitude, | ||
scale:1 | ||
}) | ||
} | ||
}); | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"navigationBarTitleText": "当前地图位置" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<view class="container" id="map"> | ||
</view> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#map { | ||
padding: 40rpx; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
var util = require('../../utils/util.js') | ||
Page({ | ||
data: { | ||
logs: [] | ||
}, | ||
onLoad: function () { | ||
this.setData({ | ||
logs: (wx.getStorageSync('logs') || []).map(function (log) { | ||
return util.formatTime(new Date(log)) | ||
}) | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"navigationBarTitleText": "查看启动日志" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<!--logs.wxml--> | ||
<view class="container log-list"> | ||
<block wx:for-items="{{logs}}" wx:for-item="log"> | ||
<text class="log-item">{{index + 1}}. {{log}}</text> | ||
</block> | ||
</view> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.log-list { | ||
display: flex; | ||
flex-direction: column; | ||
padding: 40rpx; | ||
} | ||
.log-item { | ||
margin: 10rpx; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var app = getApp() | ||
Page({ | ||
data: { | ||
motto: 'Hello WeApp', | ||
userInfo: {} | ||
}, | ||
onButtonTap: function() { | ||
wx.navigateTo({ | ||
url: '../logs/logs' | ||
}) | ||
}, | ||
onLoad: function () { | ||
console.log('onLoad') | ||
var that = this | ||
//登录 | ||
wx.login({ | ||
success: function () { | ||
wx.getUserInfo({ | ||
success: function (res) { | ||
that.setData({userInfo: res.userInfo}) | ||
that.update() | ||
} | ||
}) | ||
}, | ||
fail: function (res) { | ||
console.log(res) | ||
} | ||
}); | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!--index.wxml--> | ||
<view class="container"> | ||
<view bindtap="onButtonTap" class="userinfo"> | ||
<image class="userinfo-avatar" src="{{userInfo.avatarUrl}}" background-size="cover"></image> | ||
<text class="userinfo-nickname">{{userInfo.nickName}}</text> | ||
</view> | ||
<view> | ||
<text class="user-motto">{{motto}}</text> | ||
</view> | ||
</view> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/**index.wxss**/ | ||
.container { | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: space-between; | ||
padding: 200rpx 0; | ||
box-sizing: border-box; | ||
} | ||
.userinfo { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
.userinfo-avatar { | ||
width: 128rpx; | ||
height: 128rpx; | ||
margin: 20rpx; | ||
border-radius: 50%; | ||
} | ||
.userinfo-nickname { | ||
color: #aaa; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
function formatTime(date) { | ||
var year = date.getFullYear() | ||
var month = date.getMonth() + 1 | ||
var day = date.getDate() | ||
|
||
var hour = date.getHours() | ||
var minute = date.getMinutes() | ||
var second = date.getSeconds(); | ||
|
||
|
||
return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':') | ||
} | ||
|
||
function formatNumber(n) { | ||
n = n.toString() | ||
return n[1] ? n : '0' + n | ||
} | ||
|
||
module.exports = { | ||
formatTime: formatTime | ||
} |