zoukankan      html  css  js  c++  java
  • 微信小程序位置

    wx.openLocation  获取定位打开地图,配合wx.getLocation得到的经纬度实现定位,不能单独使用

    wx.chooseLocation  根据已有的经纬度打开地图

    <view class="location-1" bindtap="open_location_1">
      定位
    </view>
    <view class="location-2"  bindtap="open_location_2">定位2</view>
     
     open_location_1(){
        console.log("我被点击了")
    
        wx.getSetting({
          success:res=>{
            console.log(res)
            if(!res.authSetting["scope.userLocation"]){
              // 未开启定位
              wx.showModal({
                title:'提示',
                content:'我们需要获取您的位置信息,为您提供更多的精彩内容',
                confirmText:"授权",
                cancelText:"取消",
                success:res=>{
                  if(res.confirm){
                    wx.openSetting({
                      success:res=>{
                        wx.getLocation({
                          type:'gcj02',
                          success:res=>{
                            console.log(res)
                            wx.openLocation({
                              latitude: res.latitude,
                              longitude:res.longitude,
                              success:res=>{
                                console.log('成功',res)
                              }
                            })
                          }
                        })
                      }
                    })
                  }else{
                    wx.showToast({
                      title: '您拒绝了授权,请在设置中开启授权定位',
                    })
                  }
                }
              })
            }else{
             wx.getLocation({
                type:'gcj02',
                success:res=>{
                  console.log(res)
                  wx.openLocation({
                    latitude: res.latitude,
                    longitude:res.longitude,
                    success:res=>{
                      console.log('成功',res)
                    }
                  })
                }
              })
            }
          }
        })
        
      },

    注意使用wx.getLocation需要在app.json中加上这个属性

    "permission": {
        "scope.userLocation": {
          "desc": "地图选点需获取您的实时位置"
        }
      },
     open_location_2(){
       var latitude= 31.82057
       var longitude= 117.22901
    
       wx.chooseLocation({
         latitude:latitude,
         longitude:longitude,
         success:res=>{
           console.log(res)
         },fail:err=>{
           if(err.errMsg=="chooseLocation:fail auth deny"){
            wx.openSetting({
             success:res=>{
               console.log(res)
               if(!res.authSetting["scope.userLocation"]){
                 wx.showToast({
                   title: '你拒绝了授权,请在设置中自行授权定位',
                 })
               }else{
                wx.chooseLocation({
                  latitude:latitude,
                  longitude:longitude,
                  success:res=>{
                    console.log(res)
                  }
                })
               }
             }
            })
           }
         }
       })
      },
  • 相关阅读:
    Sql2008 全文索引 简明教程
    sql server 全文检索 使用
    数据库分词查询的优缺点以及英文和中文各自的分词方法(一)
    win10中打开SQL Server配置管理器方法
    Asp.net 中高亮显示搜索关键字简单方法
    EntityFramework优缺点
    LoadXml载入Xhtml文件速度很慢
    c#无限循环线程如何正确退出
    线程的等待方法:join
    C#如何优雅的结束一个线程
  • 原文地址:https://www.cnblogs.com/shanchui/p/13379199.html
Copyright © 2011-2022 走看看