<template>
<gracePage :customHeader="false">
<!-- 页面主体 -->
<view slot="gBody">
<view class="">
<map style="width:750rpx; height:300px;" :scale="16" @markertap="markertap"
:latitude="latitude" :longitude="longitude" :markers="covers"></map>
</view>
<view class="grace-body">
<view class="grace-title grace-margin-top ">
<view class="grace-title-border"></view>
<text class="grace-title-text grace-blue">周边便利店</text>
<text class="grace-text-small grace-gray">grace.hcoder.net</text>
</view>
<view class="grace-list grace-margin-top">
<view class="grace-list-items"
v-for="(item, index) in nearShops" :key="index" :data-index="index">
<view class="grace-list-body">
<view class="grace-list-title">
<text class="grace-list-title-text">{{item.title}}</text>
</view>
<view class="grace-list-body-desc" style="margin-top:3px;">
<text>距离 : {{item._distance}} 米 \n{{item.address}}</text>
</view>
</view>
<view class="map-btns grace-nowrap">
<view class="map-btn" @tap="pathfinding" :data-index="index">
<text class="map-btn-icon grace-icons icon-pathfinding grace-blue"></text>
<text class="map-btn-text">导航</text>
</view>
<view class="map-btn" v-if="item.tel.length >= 7" :data-index="index" @tap="phoneCall">
<text class="map-btn-icon grace-icons icon-tel grace-blue"></text>
<text class="map-btn-text">电话</text>
</view>
<view class="map-btn" v-else>
<text class="map-btn-icon grace-icons icon-tel grace-gray"></text>
<text class="map-btn-text grace-gray">电话</text>
</view>
</view>
</view>
</view>
</view>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/components/gracePage.vue";
var graceJS = require('@/Grace.JS/grace.js');
export default {
data() {
return {
latitude : 39.909, // 纬度
longitude : 116.39742 ,//经度,
covers : [],
locationName : '',
nearShops : []
}
},
onLoad:function(){
uni.showLoading({});
// 默认情况下获取当前位置
// 请仔细阅读 注意事项!!
// https://uniapp.dcloud.io/api/location/location
uni.getLocation({
type: 'gcj02',
success:(res)=>{
console.log('当前位置的经度:' + res.longitude);
console.log('当前位置的纬度:' + res.latitude);
this.latitude = res.latitude;
this.longitude = res.longitude;
// 根据精度纬度获取详细地址
graceJS.get(
'https://grace.hcoder.net/txMap/txMap.php?method=location2address&latitude='+res.latitude+'&longitude='+res.longitude,
{m:"getJson"},
{},
(res)=>{
console.log(res);
if(res.status == 'ok'){
this.locationName = res.data.address;
}
}
);
// 获取到当前坐标后获取周边的商店
graceJS.get(
'https://grace.hcoder.net/txMap/txMap.php?method=search&kwd=便利店&boundary=nearby('+res.latitude+','+res.longitude+',1000)',
{m:"getJson"},
{},
(res)=>{
console.log(res);
if(res.status == 'ok'){
this.nearShops = res.data;
for(let i = 0; i < res.data.length; i++){
this.covers.push({
id : i,
latitude : res.data[i].location.lat,
longitude : res.data[i].location.lng,
iconPath : '../../static/location.png',
width : 28,
height : 28,
callout : {content:res.data[i].title, padding:10, display:'ALWAYS'}
});
}
console.log(this.covers);
}
uni.hideLoading();
}
);
},
fail:function(){
uni.hideLoading();
}
});
},
methods:{
// 拨打电话
phoneCall:function(e){
var index = e.currentTarget.dataset.index;
console.log(this.nearShops[index].tel);
uni.makePhoneCall({
phoneNumber: this.nearShops[index].tel
});
},
// 标记点击
markertap : function(e){
console.log(e);
var index = e.markerId;
uni.openLocation({
latitude : this.covers[index].latitude,
longitude : this.covers[index].longitude,
name : this.nearShops[index].title,
success: function () {
console.log('success');
}
});
},
// 点击导航按钮
pathfinding : function(e){
var index = e.currentTarget.dataset.index;
uni.openLocation({
latitude : this.nearShops[index].location.lat,
longitude : this.nearShops[index].location.lng,
name : this.nearShops[index].title,
success: function () {
console.log('success');
}
});
}
},
components:{
gracePage
}
}
</script>
<style>
.grace-icons{font-size:38rpx;}
.grace-list-title-text{font-size:32rpx !important;}
.map-btns{width:160rpx; margin-left:20rpx; flex-shrink:0;}
.map-btn{width:80rpx; font-size:50rpx; line-height:60rpx;}
.map-btn-icon{line-height:55rpx; font-size:38rpx; text-align:center; width:100%; display:block;}
.map-btn-text{line-height:30rpx; font-size:24rpx; color:#8788A3; margin-top:3px; text-align:center; width:100%; display:block;}
.icon-tel{font-size:42rpx;}
</style>
<template>
<gracePage :customHeader="false">
<!-- 页面主体 -->
<view slot="gBody">
<view class="">
<map style="width:750rpx; height:300px;" :scale="16" @markertap="markertap"
:latitude="latitude" :longitude="longitude" :markers="covers"></map>
</view>
<view class="grace-body">
<view class="grace-title grace-margin-top ">
<view class="grace-title-border"></view>
<text class="grace-title-text grace-blue">周边便利店</text>
<text class="grace-text-small grace-gray">grace.hcoder.net</text>
</view>
<view class="grace-list grace-margin-top">
<view class="grace-list-items"
v-for="(item, index) in nearShops" :key="index" :data-index="index">
<view class="grace-list-body">
<view class="grace-list-title">
<text class="grace-list-title-text">{{item.title}}</text>
</view>
<text class="grace-list-body-desc" style="margin-top:3px;">距离 : {{item._distance}} 米</text>
<text class="grace-list-body-desc">{{item.address}}</text>
</view>
<view class="map-btns grace-nowrap">
<view class="map-btn" @tap="pathfinding" :data-index="index">
<text class="map-btn-icon grace-icons grace-blue"></text>
<text class="map-btn-text">导航</text>
</view>
<view class="map-btn" v-if="item.tel.length >= 7" :data-index="index" @tap="phoneCall">
<text class="map-btn-icon grace-icons grace-blue"></text>
<text class="map-btn-text">电话</text>
</view>
<view class="map-btn" v-else>
<text class="map-btn-icon grace-icons grace-gray"></text>
<text class="map-btn-text grace-gray">电话</text>
</view>
</view>
</view>
</view>
</view>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/weexComponents/gracePage.nvue";
var graceJS = require('@/Grace.JS/grace.js');
export default {
data() {
return {
latitude : 39.909, // 纬度
longitude : 116.39742 ,//经度,
covers : [],
locationName : '',
nearShops : []
}
},
onLoad:function(){
uni.showLoading({});
// 默认情况下获取当前位置
// 请仔细阅读 注意事项!!
// https://uniapp.dcloud.io/api/location/location
uni.getLocation({
type: 'gcj02',
success:(res)=>{
console.log('当前位置的经度:' + res.longitude);
console.log('当前位置的纬度:' + res.latitude);
this.latitude = res.latitude;
this.longitude = res.longitude;
// 根据精度纬度获取详细地址
graceJS.get(
'https://grace.hcoder.net/txMap/txMap.php?method=location2address&latitude='+res.latitude+'&longitude='+res.longitude,
{m:"getJson"},
{},
(res)=>{
console.log(res);
}
);
// 获取到当前坐标后获取周边的商店
graceJS.get(
'https://grace.hcoder.net/txMap/txMap.php?method=search&kwd=便利店&boundary=nearby('+res.latitude+','+res.longitude+',1000)',
{m:"getJson"},
{},
(res)=>{
console.log(res);
if(res.status == 'ok'){
this.nearShops = res.data;
uni.hideLoading();
for(let i = 0; i < res.data.length; i++){
this.covers[i] = {
id : i,
latitude : res.data[i].location.lat,
longitude : res.data[i].location.lng,
iconPath : '../../static/location.png',
width : 28,
height : 28,
callout : {content:res.data[i].title, padding:10, display:'ALWAYS'}
};
}
console.log(this.covers);
}
}
);
},
fail:function(){
uni.hideLoading();
}
});
},
methods:{
// 拨打电话
phoneCall:function(e){
var index = e.currentTarget.dataset.index;
console.log(this.nearShops[index].tel);
uni.makePhoneCall({
phoneNumber: this.nearShops[index].tel
});
},
// 标记点击
markertap : function(e){
console.log(e);
var index = e.markerId;
uni.openLocation({
latitude : this.covers[index].latitude,
longitude : this.covers[index].longitude,
name : this.nearShops[index].title,
success: function () {
console.log('success');
}
});
},
// 点击导航按钮
pathfinding : function(e){
var index = e.currentTarget.dataset.index;
uni.openLocation({
latitude : this.nearShops[index].location.lat,
longitude : this.nearShops[index].location.lng,
name : this.nearShops[index].title,
success: function () {
console.log('success');
}
});
}
},
components:{
gracePage
}
}
</script>
<style>
.grace-icons{font-size:38rpx;}
.grace-list-title-text{font-size:32rpx !important;}
.map-btns{width:160rpx; margin-left:20rpx;}
.map-btn{width:80rpx; font-size:50rpx; line-height:60rpx;}
.map-btn-icon{line-height:55rpx; font-size:38rpx; text-align:center;}
.map-btn-text{line-height:30rpx; font-size:24rpx; color:#8788A3; margin-top:3px; text-align:center;}
.icon-tel{font-size:42rpx;}
</style>
.wxml
<gracePage customHeader="{{false}}">
<!-- 页面主体 -->
<view slot="gBody">
<view class="">
<map style="width:750rpx; height:300px;" scale="{{16}}" bindmarkertap="markertap"
latitude="{{latitude}}" longitude="{{longitude}}" markers="{{covers}}"></map>
</view>
<view class="grace-body">
<view class="grace-title grace-margin-top ">
<view class="grace-title-border"></view>
<text class="grace-title-text grace-blue">周边便利店</text>
<text class="grace-text-small grace-gray">grace.hcoder.net</text>
</view>
<view class="grace-list grace-margin-top">
<view class="grace-list-items"
wx:for="{{nearShops}}" wx:key="index" data-index="{{index}}">
<view class="grace-list-body">
<view class="grace-list-title">
<text class="grace-list-title-text">{{item.title}}</text>
</view>
<view class="grace-list-body-desc" style="margin-top:3px;">
<text>距离 : {{item._distance}} 米 \n{{item.address}}</text>
</view>
</view>
<view class="map-btns grace-nowrap">
<view class="map-btn" bindtap="pathfinding" data-index="{{index}}">
<text class="map-btn-icon grace-icons icon-pathfinding grace-blue"></text>
<text class="map-btn-text">导航</text>
</view>
<view class="map-btn" wx:if="{{item.tel.length >= 7}}" data-index="{{index}}" bindtap="phoneCall">
<text class="map-btn-icon grace-icons icon-tel grace-blue"></text>
<text class="map-btn-text">电话</text>
</view>
<view class="map-btn" wx:else>
<text class="map-btn-icon grace-icons icon-tel grace-gray"></text>
<text class="map-btn-text grace-gray">电话</text>
</view>
</view>
</view>
</view>
</view>
</view>
</gracePage>.js
var graceJS = require('../../Grace.JS/grace.js');
Page({
data: {
latitude : 39.909, // 纬度
longitude : 116.39742 ,//经度,
covers : [],
locationName : '',
nearShops : []
},
onLoad:function(){
wx.showLoading({});
// 默认情况下获取当前位置
wx.getLocation({
success:(res)=>{
console.log('当前位置的经度:' + res.longitude);
console.log('当前位置的纬度:' + res.latitude);
this.setData({latitude:res.latitude, longitude:res.longitude});
// 根据精度纬度获取详细地址
graceJS.get(
'https://grace.hcoder.net/txMap/txMap.php?method=location2address&latitude='+res.latitude+'&longitude='+res.longitude,
{m:"getJson"},
{},
(res)=>{ console.log(res); }
);
// 获取到当前坐标后获取周边的商店
graceJS.get(
'https://grace.hcoder.net/txMap/txMap.php?method=search&kwd=便利店&boundary=nearby('+res.latitude+','+res.longitude+',1000)',
{m:"getJson"},
{},
(res)=>{
console.log(res);
if(res.status == 'ok'){
for(let i = 0; i < res.data.length; i++){
this.data.covers.push({
id : i,
latitude : res.data[i].location.lat,
longitude : res.data[i].location.lng,
iconPath : '../../static/location.png',
width : 28,
height : 28,
callout : {content:res.data[i].title, padding:10, display:'ALWAYS'}
});
}
this.setData({nearShops:res.data, covers:this.data.covers});
}
wx.hideLoading();
});
},
fail:function(){
wx.hideLoading();
},
});
},
// 拨打电话
phoneCall:function(e){
var index = e.currentTarget.dataset.index;
wx.makePhoneCall({
phoneNumber: this.data.nearShops[index].tel
});
},
// 标记点击
markertap : function(e){
console.log(e);
var index = e.markerId;
wx.openLocation({
latitude : this.data.covers[index].latitude,
longitude : this.data.covers[index].longitude,
name : this.data.nearShops[index].title,
success: function () {
console.log('success');
}
});
},
// 点击导航按钮
pathfinding : function(e){
var index = e.currentTarget.dataset.index;
wx.openLocation({
latitude : this.data.nearShops[index].location.lat,
longitude : this.data.nearShops[index].location.lng,
name : this.data.nearShops[index].title,
success: function () {
console.log('success');
}
});
}
});.json
{
"usingComponents": {
"gracePage": "../../graceUI/components/gracePage"
}
}.wxss
.grace-icons{font-size:38rpx;}
.grace-list-title-text{font-size:32rpx !important;}
.map-btns{width:160rpx; margin-left:20rpx; flex-shrink:0;}
.map-btn{width:80rpx; font-size:50rpx; line-height:60rpx;}
.map-btn-icon{line-height:55rpx; font-size:38rpx; text-align:center; width:100%; display:block;}
.map-btn-text{line-height:30rpx; font-size:24rpx; color:#8788A3; margin-top:3px; text-align:center; width:100%; display:block;}
.icon-tel{font-size:42rpx;}