1***@qq.com
1***@qq.com
  • 发布:2023-05-17 10:51
  • 更新:2023-05-17 10:51
  • 阅读:192

app 设置地图的 polyline时 Cannot read property 'map' of undefined

分类:uni-app
<template>  
    <view class="content">  
        <map class="map" :show-compass="true" :enable-zoom="true" :enable-scroll="true" :scale="15"  
            :polyline="polyline" :show-location="true" :latitude="location.latitude" :longitude="location.longitude"  
            :markers="markers" />  
        <button @tap="test">请求规划</button>  
    </view>  
</template>  

<script>  
    export default {  
        data() {  
            return {  
                polyline: [],  
                location: {  
                    latitude: 0,  
                    longitude: 0  
                },  
                markers: []  
            }  
        },  
        async onShow() {  
            const rest = uni.getAppAuthorizeSetting()  
            const {  
                longitude,  
                latitude  
            } = await this.getLocation()  
            this.location = {  
                longitude,  
                latitude  
            }  
            this.setCurrentLocationMarks(latitude, longitude)  
        },  
        methods: {  
            test() {  
                const {  
                    longitude,  
                    latitude  
                } = this.location  
                this.getDriverLine(this.location, {  
                    longitude,  
                    latitude: latitude + 0.3  
                })  
            },  
            setCurrentLocationMarks(latitude, longitude) {  
                this.markers = [{  
                    id: 1,  
                    iconPath: "https://api.iconify.design/carbon:location-filled.svg",  
                    with: 30,  
                    height: 30,  
                    latitude,  
                    longitude,  
                }]  
            },  

            getLocation() {  
                return new Promise((resolve) => {  
                    uni.getLocation({  
                        type: 'gcj02',  
                        geocode: true,  
                        complete: (res) => {  
                            const {  
                                latitude,  
                                longitude,  
                                address  
                            } = res  
                            resolve({  
                                latitude,  
                                longitude,  
                                address  
                            })  
                        }  
                    })  
                })  
            },  

            getDriverLine(startPoint, endPoint) {  
                const origin = `${startPoint.longitude},${startPoint.latitude}`  
                const destination = `${endPoint.longitude},${endPoint.latitude}`  
                uni.request({  
                    url: `http://xxxx`,  
                    method: "GET",  
                    data: {  
                        startPoint,  
                        endPoint  
                    },  
                    success: (res) => {  
                        this.polyline = [{  
                            points: res.data.points,  
                            color: "#0091ff",  
                            width: 6,  
                        }]  
                    }  
                })  

            }  
        }  
    }  
</script>  

点击 请求规划后 控制台 出现

    TypeError: Cannot read property 'map' of undefined  
    at file:///storage/emulated/0/Android/data/uni.UNIC2E9901/apps/__UNI__C2E9901/www/uni-app-view.umd.js:1:277633

manifest.json 附件中
请问大家有没有遇见过此问题 如有解决办法 请回复我谢谢

2023-05-17 10:51 负责人:无 分享
已邀请:

要回复问题请先登录注册