<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 demoAddress" :key="index"
:data-address="item" @tap="mapit">
<text class="grace-list-icon grace-icons icon-address grace-blue"></text>
<view class="grace-list-body">
<view class="grace-list-title">
<text class="grace-list-title-text">{{item}}</text>
<text class="grace-list-title-desc">点击标注</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 : [{
id : 1,
latitude : 39.909,
longitude : 116.39742,
iconPath : '../../static/location.png',
width : 38,
height : 38
}],
locationName : '',
demoAddress : [
'北京市国家体育馆',
'西安市大雁塔北广场',
'西安市高新一路25号创新大厦'
]
}
},
onLoad:function(){
// 默认情况下获取当前位置
// 请仔细阅读 注意事项!!
// 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;
this.covers = [{
id : 1,
latitude : res.latitude,
longitude : res.longitude,
iconPath : '../../static/location.png',
width : 38,
height : 38
}];
// 根据精度纬度获取详细地址
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;
}
}
);
}
});
},
methods:{
mapit : function(e){
var address = e.currentTarget.dataset.address;
this.getLocation(address);
},
// 根据详细地址计算坐标
// 后端 api php 版本 请在群文件内下载
getLocation : function(address){
graceJS.get(
'https://grace.hcoder.net/txMap/txMap.php?method=address2location&address='+address,
{m:"getJson"},
{},
(res)=>{
if(res.status == 'ok'){
var location = res.data.location;
this.latitude = location.lat;
this.longitude = location.lng;
this.covers = [{
id : 1,
latitude : location.lat,
longitude : location.lng,
iconPath : '../../static/location.png',
width : 30,
height : 30
}];
this.locationName = address;
}else{
uni.showToast({ title:"地址解析失败", icon:"none" });
}
}
);
},
// 点击标注点 打开新页面并可以调用第三方导航
markertap : function(e){
console.log(e);
uni.openLocation({
latitude : this.covers[0].latitude,
longitude : this.covers[0].longitude,
name : this.locationName,
success: function () {
console.log('success');
}
});
}
},
components:{
gracePage
}
}
</script>
<style>
.grace-icons{font-size:38rpx;}
</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 demoAddress" :key="index"
:data-address="item" @tap="mapit">
<text class="grace-list-icon grace-icons grace-blue"></text>
<view class="grace-list-body">
<view class="grace-list-title">
<text class="grace-list-title-text">{{item}}</text>
<text class="grace-list-title-desc">点击标注</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 : [{
id : 1,
latitude : 39.909,
longitude : 116.39742,
iconPath : '../../static/location.png',
width : 38,
height : 38
}],
locationName : '',
demoAddress : [
'北京市国家体育馆',
'西安市大雁塔北广场',
'西安市高新一路25号创新大厦'
]
}
},
onLoad:function(){
// 默认情况下获取当前位置
// 请仔细阅读 注意事项!!
// 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;
this.covers = [{
id : 1,
latitude : res.latitude,
longitude : res.longitude,
iconPath : '../../static/location.png',
width : 38,
height : 38
}];
// 根据精度纬度获取详细地址
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;
}
}
);
}
});
},
methods:{
mapit : function(e){
var address = e.currentTarget.dataset.address;
this.getLocation(address);
},
// 根据详细地址计算坐标
// 后端 api php 版本 请在群文件内下载
getLocation : function(address){
graceJS.get(
'https://grace.hcoder.net/txMap/txMap.php?method=address2location&address='+address,
{m:"getJson"},
{},
(res)=>{
if(res.status == 'ok'){
var location = res.data.location;
this.latitude = location.lat;
this.longitude = location.lng;
this.covers = [{
id : 1,
latitude : location.lat,
longitude : location.lng,
iconPath : '../../static/location.png',
width : 30,
height : 30
}];
this.locationName = address;
}else{
uni.showToast({ title:"地址解析失败", icon:"none" });
}
}
);
},
// 点击标注点 打开新页面并可以调用第三方导航
markertap : function(e){
console.log(e);
uni.openLocation({
latitude : this.covers[0].latitude,
longitude : this.covers[0].longitude,
name : this.locationName,
success: function () {
console.log('success');
}
});
}
},
components:{
gracePage
}
}
</script>
<style>
.grace-icons{font-size:38rpx;}
</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">
<view class="grace-list-items" wx:for="{{demoAddress}}" wx:key="index" data-address="{{item}}" bindtap="mapit">
<text class="grace-list-icon grace-icons icon-address grace-blue"></text>
<view class="grace-list-body">
<view class="grace-list-title">
<text class="grace-list-title-text">{{item}}</text>
<text class="grace-list-title-desc">点击标注</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 : [{
id : 1,
latitude : 39.909,
longitude : 116.39742,
iconPath : '../../static/location.png',
width : 38,
height : 38
}],
locationName : '',
demoAddress : [
'北京市国家体育馆',
'西安市大雁塔北广场',
'西安市高新一路25号创新大厦'
]
},
onLoad:function(){
wx.getLocation({
type: 'gcj02',
success:(res)=>{
console.log('当前位置的经度:' + res.longitude);
console.log('当前位置的纬度:' + res.latitude);
this.latitude = res.latitude;
this.longitude = res.longitude;
var covers = [{
id : 1,
latitude : res.latitude,
longitude : res.longitude,
iconPath : '../../static/location.png',
width : 38,
height : 38
}];
this.setData({latitude:res.latitude, longitude:res.longitude, covers:covers});
// 根据精度纬度获取详细地址
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.setData({locationName:res.data.address});
}
}
);
}
});
},
mapit : function(e){
var address = e.currentTarget.dataset.address;
this.getLocation(address);
},
// 根据详细地址计算坐标
// 后端 api php 版本 请在群文件内下载
getLocation : function(address){
graceJS.get(
'https://grace.hcoder.net/txMap/txMap.php?method=address2location&address='+address,
{m:"getJson"},
{},
(res)=>{
if(res.status == 'ok'){
var location = res.data.location;
var covers = [{
id : 1,
latitude : location.lat,
longitude : location.lng,
iconPath : '../../static/location.png',
width : 30,
height : 30
}];
this.setData({latitude:location.lat, longitude:location.lng, covers:covers, locationName:address});
}else{
wx.showToast({ title:"地址解析失败", icon:"none" });
}
}
);
},
// 点击标注点 打开新页面并可以调用第三方导航
markertap : function(e){
console.log(e);
wx.openLocation({
latitude : this.data.covers[0].latitude,
longitude : this.data.covers[0].longitude,
name : this.data.locationName,
success: function () {
console.log('success');
}
});
}
});.json
{
"usingComponents": {
"gracePage": "../../graceUI/components/gracePage"
}
}.wxss
.grace-icons{font-size:38rpx;}