使用的百度地圖。必須先使用百度地圖獲取目標位置和使用百度地圖獲取目標位置,然后在通過百度地圖的獲取我和目標的位置。由于異步的原因,所以我使用了定時器解決,不過性能肯定不好,如何使用asyncawait或者promise代替定時器呢?代碼片段如下://獲取目標位置varmyGeo=newBMap.Geocoder();//根據(jù)中地址名查經(jīng)緯度myGeo.getPoint(scope.targetname,function(point){if(point){scope.target=point;}else{toast("您選擇地址沒有解析到結(jié)果!");}},scope.cityname);//獲取我的位置vargeolocation=newBMap.Geolocation();geolocation.getCurrentPosition(function(r){if(this.getStatus()==BMAP_STATUS_SUCCESS){//alert('您的位置:'+r.point.lng+','+r.point.lat);scope.myadd=newBMap.Point(r.point.lng,r.point.lat);//console.log(scope.myadd,"我的位置")}else{alert("定位失敗");}},{enableHighAccuracy:true})//獲取我和目標的位置setTimeout(function(){if(scope.myadd!=""&&scope.target!=""){varmap=newBMap.Map("l-map");map.centerAndZoom(newBMap.Point(scope.target.lng,scope.target.lat),11);varwalking=newBMap.WalkingRoute(map,{renderOptions:{map:map,panel:"r-result",autoViewport:true}});walking.search(scope.myadd,scope.target);}},1000);
如何使用async await或者promise代替定時器呢?
慕尼黑8549860
2019-05-20 18:29:30