1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > springboot8==调用百度地图API从浏览器获取经纬度 后端使用geodesy依赖计算配送距离

springboot8==调用百度地图API从浏览器获取经纬度 后端使用geodesy依赖计算配送距离

时间:2022-01-06 10:46:42

相关推荐

springboot8==调用百度地图API从浏览器获取经纬度 后端使用geodesy依赖计算配送距离

见百度地图API调用文档

jspopularGL | 百度地图API SDK

================

<!--引入百度地图API用于从浏览器获取当前经纬度--><script type="text/javascript"src="http://api./api?v=2.0&ak=CoeKSNi3O0VoiopZZTwGA3HFT9AjcWGX"></script>

===============

<span><img src="./images/time.png"/> 距离{{userLocation}}km</span><span><img src="./images/money.png"/> 配送费{{sendMoney}}元</span><span><img src="./images/location.png"/> 预计时长{{sendTime}}min</span>

=========

//默认值userLocation: 1,sendMoney: 1,sendTime: 1,

=======

getLocation() {let _this = thisvar map = new BMap.Map("allmap");var geolocation = new BMap.Geolocation();geolocation.getCurrentPosition(async function (r) {if (this.getStatus() == BMAP_STATUS_SUCCESS) {var mk = new BMap.Marker(r.point);map.addOverlay(mk);map.panTo(r.point);alert('您的位置,是否允许使用:' + r.point.lng + ',' + r.point.lat);const location = {//往后端传输经纬度latitude: r.point.lng,longitude: r.point.lat}const res = await getLocation2(location)// alert(res.code)if (res.code === 1) {_this.userLocation = res.data_this.sendMoney = _this.userLocation * 1_this.sendTime = _this.userLocation * 2console.log(_this.userLocation + '千米')}} else {alert('failed' + this.getStatus());}});},

===========

//获取当前距离function getLocation2(location) {return $axios({'url': '/dish/getLocation2','method': 'get',params: location})}

==========

/*** 根据前端传回的经纬度,计算获取距离*/@GetMapping("/getLocation2")public R getLocation(String latitude, String longitude) {log.info("经纬度" + latitude + "经纬度" + longitude);double a = Double.parseDouble(latitude);//用户当前坐标GlobalCoordinates userSource = new GlobalCoordinates(Double.parseDouble(latitude), Double.parseDouble(longitude));//店铺位置坐标 经纬度104.07274727经纬度30.57899372GlobalCoordinates businessTarget = new GlobalCoordinates(104.07274728, 30.57899372);double meterDouble = getDistanceMeter(userSource, businessTarget, Ellipsoid.Sphere);int meter = (int) meterDouble;log.info("距离多少千米" + meter / 1000);return R.success(meter / 1000);}

===========================================

。。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。