最坏是单飞
最坏是单飞
  • 发布:2019-06-24 15:47
  • 更新:2020-10-26 14:15
  • 阅读:7787

H5定位失败getLocation:fail,安卓APP就没事儿

分类:uni-app

H5应用定位会返回getLocation:fail,app中就没事儿
已经配置了腾讯地图的key

uni.getLocation({
type: 'gcj02', //返回可以用于uni.openLocation的经纬度
geocode:true,
success: function (res) {

            console.log(res);  
            var son =res.address;  
            //console.log(son);  

            that.position.lng=res.longitude;  
            that.position.lat=res.latitude;  
            that.position.address=son.district+son.street+son.streetNum+son.poiName;  
            that.defInfo.address=that.position.address;  
            uni.showToast({  
                title:'已定位到:'+that.position.address,  
                icon:'none'  
            })  
        },  
        fail:function(res){  
            console.log("err:")  
            console.log(res);  
        }});
2019-06-24 15:47 负责人:无 分享
已邀请:
最坏是单飞

最坏是单飞 (作者)

我已经搞定了,用高德地图的web服务解析坐标为地址就可以了,具体代码发大家参考下

uni.getLocation({  
                type: 'gcj02', //返回可以用于uni.openLocation的经纬度  
                geocode:true,  
                success: function (res) {  

                console.log(res);  

                var lng=res.longitude;  
                var lat=res.latitude;  

                //开始判断,如果不是app则自行解析地址  
                // #ifndef APP-PLUS   
                    uni.request({  
            url: 'https://restapi.amap.com/v3/geocode/regeo?key='+config.AMap_Key+'&location='+obj.lng+','+obj.lat,  
            method: "get",  
            dataType:"json",      
             header: {  
                'content-type': 'application/x-www-form-urlencoded' //自定义请求头信息  
            },  
            success:(res)=> {  

                    var data = res.data;  
                    console.log(data);  
                    if(data.status && data.status==1)  
                    {  
//定位到地址                       
var addstr = data.regeocode.formatted_address;  

                    }  

            },  
            fail:(res)=>{  

            }  
        })  
                // #endif  

            },  
            fail:function(res){  
                console.log("err:")  
                console.log(res);  
            }});
DCloud_UNI_GSQ

DCloud_UNI_GSQ

H5端获取定位信息,需要部署在 https 服务上,本地预览(localhost)仍然可以使用 http 协议。
无 GPS 模块的 PC 设备使用 Chrome 浏览器的时候,位置信息是连接谷歌服务器获取的,国内用户可能获取位置信息失败。

最坏是单飞

最坏是单飞 (作者)

谢谢,我使用火狐测试一下,目前是https的

1***@qq.com

1***@qq.com

请问作者问题解决了吗。?

1***@163.com

1***@163.com

请问一下 高德地图的web服务解析坐标所使用的obj.lng和obj.lat 是在哪获取的呢

该问题目前已经被锁定, 无法添加新回复