• uniapp之使用map组件显示接收过来的经纬度


    目录

    前言

    效果图

    提示

    总代码

    分析

    1.显示自己位置的属性

    2.markers 点标记


    前言

    由于项目的需求,我需要从主页面接收经纬度,并渲染至地图上面,同时呢,也要在该位置上显示图标标记点(红色),与此同时也要显示自己位置(蓝色点),这个简单的功能就不需要使用高德地图或者腾讯地图,因为uni-app官网就有这个功能

    map组件官网

    效果图

    提示

    它会报 

    : width and heigth of marker id 0 are required

     

    翻译:

    • 标记id为0的宽度和高度是必需的

    这个是报渲染层问题,通常只要不影响代码运行就不用管它,大哥们,如果有人知道怎么解决的话,请在下面留言,因为我不会,(*^▽^*)

    总代码

    1. <script>
    2. export default {
    3. data() {
    4. return {
    5. id: 0, // 使用 marker点击事件 需要填写id
    6. title: 'map',
    7. latitude: '',
    8. longitude: '',
    9. markers: []
    10. }
    11. },
    12. onLoad(option) {
    13. const maplatlng = JSON.parse(decodeURIComponent(option.item));
    14. this.latitude = maplatlng.stationLat
    15. this.longitude = maplatlng.stationLng
    16. let arr = [{
    17. id: 0,
    18. longitude: this.longitude,
    19. latitude: this.latitude,
    20. name: this.stationName
    21. }]
    22. let markers = []
    23. for (var i = 0; i < arr.length; i++) {
    24. markers = markers.concat({
    25. id: arr[i].id,
    26. latitude: arr[i].latitude, //纬度
    27. longitude: arr[i].longitude, //经度
    28. callout: { //自定义标记点上方的气泡窗口 点击有效
    29. content: arr[i].name, //文本
    30. color: '#ffffff', //文字颜色
    31. fontSize: 10, //文本大小
    32. borderRadius: 2, //边框圆角
    33. bgColor: '#00c16f', //背景颜色
    34. display: 'ALWAYS', //常显
    35. },
    36. })
    37. }
    38. this.markers = markers
    39. console.log(this.markers)
    40. console.log('首页传递给地图页面的数据', this.latitude, this.longitude);
    41. },
    42. methods: {}
    43. }
    44. script>
    45. <style scoped lang="scss">
    46. style>

    分析

    1.显示自己位置的属性

    show-location :默认false  可直接写  show-location="true"  或 show-location  

    2.markers 点标记

     markers = markers.concat

    concat():是一种字符串的方法,用于将字符串连接在一起,它不会更改原字符串的值,返回的是一个新字符串

    3.JSON.parse(decodeURIComponent(option.item))

    maplatlng是接收 主页面传递过来的参数

  • 相关阅读:
    log4j.properties支持不同包日志分文件打印
    arm开发板裸板代码初始化lcd结构体为啥直接赋值不能运行。
    PDF软件PDF Extra Premium + Ultimate 9.30.56026
    秋天的第一个存储过程
    vue跨域proxy详解
    投资性大于游戏性 NFT游戏到底是不是门好生意
    鼎盛合:adc芯片的五种结构
    vue-cli搭建uniapp项目过程及踩坑记录
    使用VMware搭建OceanStor_eStor存储超详细教程
    IPV6地址详解
  • 原文地址:https://blog.csdn.net/LJM51200/article/details/127970210