4***@qq.com
4***@qq.com
  • 发布:2020-04-08 10:37
  • 更新:2023-08-07 16:06
  • 阅读:1310

getCenterLocation获取不到中心点

分类:uni-app

<template>  
    <view>  
        <map id="myMap" class="map" :show-location="true" :latitude="lat" :longitude="lng" @regionchange="regionchange">  
        </map>  
        <view>lat:{{lat}}</view>  
        <view>lng:{{lng}}</view>  
    </view>  
</template>  

<script>  
    var app = getApp();  
    export default {  
        data() {  
            return {  
                lat:'',  
                lng:''  
            }  
        },  
        onShow() {  
            var that = this;  
            uni.getLocation({  
                type: 'gcj02',  
                success: res => {  
                    console.log(JSON.stringify(res))  
                    that.lat = res.latitude  
                    that.lng = res.longitude  
                },  
                fail: () => {},  
                complete: () => {}  
            });  
        },  
        onload(){  
        },  
        onReady() {  
            this.map = uni.createMapContext('myMap', this);  
        },  
        methods: {  
            regionchange(e){  
                this.getLngLat();  
            },  
            //获取地图中心点  
            getLngLat(){  
                               var that = this;  
                this.map.getCenterLocation({  
                    success(res) {  
                        console.log(JSON.stringify(res))  
                        that.lat= res.latitude  
                        that.lng= res.longitude  
                    }  
                })  
            },  
        },  

    }  
</script>  

<style>  
    .map {  
        width: 100%;  
        height: 1000rpx;  
    }  
</style>  
2020-04-08 10:37 负责人:无 分享
已邀请:
1***@qq.com

1***@qq.com

请问解决了吗?我也遇到相同的问题

蒙古野驴

蒙古野驴

请问解决了吗?我也遇到相同的问题

this_one

this_one

延迟几毫秒获取。

要回复问题请先登录注册