uniapp之定位当前位置(Location,腾讯地图,javascript)
第⼀种 uniapp
uniapp 封装的⽅法可以拿到城,市,县,经纬度。
实例:
//获取位置
GetLOcation:function(){
var that =this;
type:'gcj02',
success:(res)=>{
console.log(res)
var latitude =parseFloat(res.latitude);
var longitude =parseFloat(res.longitude);
}
});
},
官⽹地址:uniapp.dcloud.io/api/location/location?id=%e6%b3%a8%e6%84%8f
第⼆种: javascript iframe⽅法
下⾯的操作如果你是vue的就直接引⼊到index.html⽂件中。
如果是uni-app就⽐较⿇烦了:
1.⾸先新建⼀个template.h5.html⽂件;
2.在manifest.json -> 源码视图 -> h5 -> 添加 “template” : “template.h5.html”
在创建⽂件中引⼊:
<iframe id="geoPage" width=0 height=0 frameborder=0  scrolling="no"
src="apis.map.qq/tools/geolocation?key=腾讯地图key&referer=myapp">
springboot实现视频上传
</iframe>
在 body 中添加
<div v-html="str"></div>
在要使⽤的⽂件中添加下⾯代码:
var options ={
enableHighAccuracy:true,
maximumAge:30000,
timeout:12000
}
window.locationCallback=function(err, position){
if(err){
showError(err);
return;
}
mysql分页插件
showPosition(position);
}
this.str ='<iframe src="javascript:(function(){ '+
'CurrentPosition('+
'function(position){parent && parent.locationCallback && parent.locationCallback(null,position);}, '+
'function(err){parent && parent.locationCallback && parent.locationCallback(err);}, '+
'{enableHighAccuracy : '+ ableHighAccuracy +', maximumAge : '+ options.maximumAge +', timeout :'+    options.timeout +'})'+
';})()" ></iframe>';
window.showPosition=function(position){
var lat = ds.latitude;//纬度
var lag = ds.longitude;//经度
// var lags =  position.address.province;//城市名称
// alert(lags)
// alert('纬度:' + lat + ',经度:' + lon)
}
window.showError=function(error){
de){
case error.PERMISSION_DENIED:
alert('⽤户不允许地理定位!');
break;
case error.POSITION_UNAVAILABLE:
alert('⽆法获取当前位置!');
break;
case error.TIMEOUT:
alert('操作超时!');
break;
position和location的区别case error.UNKNOWN_ERROR:
alert('未知错误!');
break;
}
}
uart是同步通信还是异步通信第三种: 腾讯地图
⽀持 浏览器,⼿机端,app 端⽬前不太⽀持。
先去腾讯地图官⽅申请 key 值 然后到项⽬中的 manifest.json ⽂件中的 h5 配置中添加你的腾讯地图 key值腾讯地图 API 官⽅地址:lbs.qq/
在 项⽬中的 template.h5.html ⽂件中引⼊
双符号位补码移位规则
<script charset="utf-8" src="3gimg.qq/lightmap/components/geolocation/geolocation.min.js"></script>
<script charset="utf-8" src="map.qq/api/js?p&key=腾讯开发者key值"></script>
应⽤实例:
let that =this
var geolocation =new qq.maps.Geolocation("腾讯开发者 key 值","myapp");
var options ={
timeout:8000//延时
};
// 定位成功之后调⽤的⽅法
function showPosition(position){
console.log(position)
sql server数据库脱机let lat = position.lat;
let lng = position.lng;
}
function showErr(){
// alert('定位失败,请稍后重试');
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。