uniapp地图组件

87 篇文章 1 订阅
31 篇文章 0 订阅
  <map style="width: 100%; height: 300px;" :latitude="latitude" :longitude="longitude" :markers="covers">
    </map>
    <button @click="getMapLocation">获取位置</button>
    <text>{{address}}</text>

      getMapLocation() {
        uni.getLocation({
          type: 'wgs84',
          success: function(res) {
            console.log('当前位置的经度:' + res.longitude);
            console.log('当前位置的纬度:' + res.latitude);
          }
        });
        uni.chooseLocation({
          success: (res) => {
            console.log(res);
            this.address = res.name
            // this.getRegionFn(res);
          },
          fail: () => {
            // 如果用uni.chooseLocation没有获取到地理位置,则需要获取当前的授权信息,判断是否有地理授权信息
            uni.getSetting({
              success: (res) => {
                console.log(res);
                var status = res.authSetting;
                if (!status['scope.userLocation']) {
                  // 如果授权信息中没有地理位置的授权,则需要弹窗提示用户需要授权地理信息
                  uni.showModal({
                    title: "是否授权当前位置",
                    content: "需要获取您的地理位置,请确认授权,否则地图功能将无法使用",
                    success: (tip) => {
                      if (tip.confirm) {
                        // 如果用户同意授权地理信息,则打开授权设置页面,判断用户的操作
                        uni.openSetting({
                          success: (data) => {
                            // 如果用户授权了地理信息在,则提示授权成功
                            if (data.authSetting['scope.userLocation'] === true) {
                              uni.showToast({
                                title: "授权成功",
                                icon: "success",
                                duration: 1000
                              })
                              // 授权成功后,然后再次chooseLocation获取信息
                              uni.chooseLocation({
                                success: (res) => {
                                  console.log("详细地址", res);
                                  // this.getRegionFn(res);
                                }
                              })
                            } else {
                              uni.showToast({
                                title: "授权失败",
                                icon: "none",
                                duration: 1000
                              })
                            }
                          }
                        })
                      }
                    }
                  })
                }
              },
              fail: (res) => {
                uni.showToast({
                  title: "调用授权窗口失败",
                  icon: "none",
                  duration: 1000
                })
              }
            })
          }
        });
      },
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
uniapp地图组件是一个用于展示地图组件,它是使用vue.js开发的一个前端框架。开发者可以使用一套代码编写应用,并发布到多个平台,包括iOS、Android、Web以及各种小程序和快应用平台。 地图组件使用腾讯地图来展示地图,并且可以通过定位API(uni.getLocation)获取坐标信息。在uniapp中使用地图组件时,需要注意经纬度必填,如果不填,则默认值是北京的经纬度。 使用uniapp地图组件的基本使用方法是将map组件添加到页面中,并设置相应的属性。通过设置属性,可以实现地图的缩放、中心点位置、标记点等功能。具体的属性设置可以参考uniapp的官方文档。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [uniapp的map地图组件介绍](https://blog.csdn.net/weixin_67490903/article/details/126013460)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [uniapp中map组件的详细总结,含文字气泡、点击定位等(附全部源码)](https://blog.csdn.net/weixin_56740218/article/details/125612958)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值