Weex开发之地图篇的具体使用(8)

private RouteTask.OnRouteCalculateListener calculateListener = new RouteTask.OnRouteCalculateListener() { @Override public void onRouteCalculate(RideRouteResult result, int code) { HashMap<String, Object> res = new HashMap<>(2); if (code == 1000 && result != null) { Map<String, Object> data = new HashMap<>(1); data.put("mapLines", getLatLngList(result.getPaths().get(0), routeTask.getStartPoint(), routeTask.getEndPoint())); res.put("result", "success"); res.put("data", data); } else { res.put("result", "fail"); } String dataJson = new Gson().toJson(res); NotifyDataManager.getInstance().postMessage("mapLines", dataJson); WXLogUtils.d("RideRouteResult Json: " + dataJson); } }; routeTask.addRouteCalculateListener(calculateListener); /** * 通过首尾经纬度计算走路规划路径中所有经纬度 * * @param fromLat * @param fromLng * @param toLat * @param toLng */ @JSMethod public void searchRidingRouteFromLat(float fromLat, float fromLng, float toLat, float toLng) { LocationEntity fromLe = new LocationEntity(); fromLe.lat = fromLat / 1e6; fromLe.lng = fromLng / 1e6; LocationEntity toLe = new LocationEntity(); toLe.lat = toLat / 1e6; toLe.lng = toLng / 1e6; if (routeTask == null) { routeTask = RouteTask.getInstance(mWXSDKInstance.getContext()); routeTask.addRouteCalculateListener(calculateListener); } routeTask.search(fromLe, toLe); }

5.3 骑行路径Web实现

let stream = weex.requireModule('stream') stream.fetch({ timeout:20000, method: 'GET', url: 'https://restapi.amap.com/v4/direction/bicycling?key=87453539f02a65cd6585210fa2e64dc9&origin='+fromLng/1000000+','+fromLat/1000000+'&destination='+toLng/1000000+','+toLat/1000000, }, (response) => { if (response.status == 200) { let apiData = JSON.parse(response.data) if(apiData.data){ var polyline= new Array(); polyline[0] = apiData.data.origin.split(","); var polylineList = apiData.data.paths['0'].steps[0].polyline.split(";"); for(var i=0;i<polylineList.length;i++) { var polylinePoint = polylineList[i].split(","); polyline.push(polylinePoint); } polyline.push(apiData.data.destination.split(",")); //字符分割 callback({"result":"success","data": {"mapLines":polyline}}); } } }, () => {})

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/6aad1e73875f62d2873f0909d7946d2b.html