<template>
<gracePage :customHeader="false">
<!-- 页面主体 -->
<view slot="gBody">
<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>
<view class="">
<map style="width:750rpx; height:300px;" :scale="16" @regionchange="regionchange" id="map"
:latitude="latitudeDef" :longitude="longitudeDef" :controls="controls"></map>
</view>
<view class="grace-margin-top grace-text-center">
<text class="grace-text-small">中心坐标 : {{center[0]}}, {{center[1]}}</text>
</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 ,//经度,
// 默认值与拖拽值分开解决 安卓赋值bug
latitudeDef : 39.909, // 纬度默认值
longitudeDef : 116.39742, // 纬度默认值
controls : [{
id : 1000,
position : {left:uni.upx2px(350), top:150, width:30, height:30},
iconPath : '../../static/location.png',
}],
locationName : '',
center : ['', '']
}
},
onLoad:function(){
uni.showLoading();
// 默认情况下获取当前位置
// 请仔细阅读 注意事项!!
// https://uniapp.dcloud.io/api/location/location
uni.getLocation({
type: 'gcj02',
success:(res)=>{
uni.hideLoading();
console.log('当前位置的经度:' + res.longitude);
console.log('当前位置的纬度:' + res.latitude);
this.latitude = res.latitude;
this.longitude = res.longitude;
this.latitudeDef = res.latitude;
this.longitudeDef = res.longitude;
this.center = [res.latitude, res.longitude];
},
fail:function(){
uni.hideLoading();
}
});
},
methods:{
regionchange : function(e){
var map = uni.createMapContext('map', this);
map.getCenterLocation({
success:(res)=>{
console.log(res);
this.center = [res.latitude, res.longitude];
}
})
}
},
components:{
gracePage
}
}
</script>
<style>
</style>
<template>
<gracePage :customHeader="false">
<!-- 页面主体 -->
<view slot="gBody">
<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>
<view class="">
<map style="width:750rpx; height:300px;" :scale="16" @regionchange="regionchange" id="map"
:latitude="latitudeDef" :longitude="longitudeDef" :controls="controls"></map>
</view>
<view class="grace-margin-top">
<text class="grace-text-small grace-text-center">中心 : {{center[0]}}, {{center[1]}}</text>
</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 ,//经度,
// 默认值与拖拽值分开解决 安卓赋值bug
latitudeDef : 39.909, // 纬度默认值
longitudeDef : 116.39742, // 纬度默认值
controls : [{
id : 1000,
position : {left:uni.upx2px(350), top:150, width:30, height:30},
iconPath : '../../static/location.png',
}],
locationName : '',
center : ['', '']
}
},
onLoad:function(){
uni.showLoading();
// 默认情况下获取当前位置
// 请仔细阅读 注意事项!!
// https://uniapp.dcloud.io/api/location/location
uni.getLocation({
type: 'gcj02',
success:(res)=>{
uni.hideLoading();
console.log('当前位置的经度:' + res.longitude);
console.log('当前位置的纬度:' + res.latitude);
this.latitude = res.latitude;
this.longitude = res.longitude;
this.latitudeDef = res.latitude;
this.longitudeDef = res.longitude;
this.center = [res.latitude, res.longitude];
},
fail:function(){
uni.hideLoading();
}
});
},
methods:{
regionchange : function(e){
var map = uni.createMapContext('map', this);
map.getCenterLocation({
success:(res)=>{
console.log(res);
this.center = [res.latitude, res.longitude];
}
})
}
},
components:{
gracePage
}
}
</script>
<style>
</style>
.wxml
<gracePage customHeader="{{false}}">
<!-- 页面主体 -->
<view slot="gBody">
<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>
<view class="">
<map style="width:750rpx; height:300px;" scale="16" bindregionchange="regionchange" id="map"
latitude="{{latitudeDef}}" longitude="{{longitudeDef}}" controls="{{controls}}"></map>
</view>
<view class="grace-margin-top grace-text-center">
<text class="grace-text-small">中心坐标 : {{center[0]}}, {{center[1]}}</text>
</view>
</view>
</gracePage>.js
var graceJS = require('../../Grace.JS/grace.js');
Page({
data: {
latitude : 39.909, // 纬度
longitude : 116.39742 ,//经度,
// 默认值与拖拽值分开解决 安卓赋值bug
latitudeDef : 39.909, // 纬度默认值
longitudeDef : 116.39742, // 纬度默认值
controls : [],
locationName : '',
center : ['', '']
},
onLoad:function(){
var system = graceJS.system();
console.log(system)
this.setData({
controls:[{
id : 1000,
position : {left:system.windowWidth/2, top:150, width:30, height:30},
iconPath : '/static/location.png'
}]
});
wx.showLoading();
// 默认情况下获取当前位置
wx.getLocation({
success:(res)=>{
wx.hideLoading();
var center = [res.latitude, res.longitude];
this.setData({
latitude:res.latitude,
longitude:res.longitude,
latitudeDef:res.latitude,
longitudeDef:res.longitude,
center:center});
},
fail:function(){
wx.hideLoading();
}
});
},
regionchange : function(e){
var map = wx.createMapContext('map', this);
map.getCenterLocation({
success:(res)=>{
console.log(res);
var center = [res.latitude, res.longitude];
this.setData({center:center});
}
})
}
});.json
{
"usingComponents": {
"gracePage": "../../graceUI/components/gracePage"
}
}