(未显示1个用户的8个中间版本) | |||
第1行: | 第1行: | ||
− | <div id="examples_center"> | + | <div id="examples_center"><!-- 页面标题 --><div class="title-hd">骑行路线规划</div><!-- 标题下子标题及简介,可有多个 --><div class="title-mi">功能场景</div><div class="wrap-mi">物流快递、出行、O2O等APP中常使用骑行路线规划功能,展示小车到目的地的路线、时间、里程信息等。</div><!-- --></div><div class="demos_wrap"><div class="header"><div class="andiord-header active">Android</div><div class="ios-header">iOS</div></div><div class="andiord-wrap wrap"><div class="wrap-wp"><div class="wrap_left"><div class="left-video"><div class="img-bg-and"></div><div class="phone-android"><div class="video-wrap infor"><div class="video-control"></div><!-- 安卓视频位置 (不写协议)--><pre>//mapopen-website-wiki.bj.bcebos.com/demos/AndroidVideos/SVID_20200530_210144_1.mp4</pre> |
− | + | </div><div class="video-icon-and"><div class="play play-and"></div><div class="stop stop-and"></div></div></div><div class="progressWrap-hide-and"></div><div id="videoControls-and"><div id="progressWrap-and"><div id="playProgress-and"></div></div></div></div><div class="left-qrCode"><!-- 安卓二维码位置 --><div class="qrCode-and">1590746640|//mapopen-website-wiki.bj.bcebos.com/demos/newqrcodes/骑行路线规划.png</div><div>扫码体验</div></div></div><div class="wrap_right"><div class="wrap_right_nav"><div class="wrap_right_nav_l"><div>使用产品</div><div><!-- 安卓使用产品下选项,可有多个 --><div class="documentA">Android地图SDK|/index.php?title=androidsdk</div><!-- --><div>></div><div class="documentA">骑行路线规划|/index.php?title=androidsdk/guide/route/bike</div></div></div><div class="wrap_right_nav_r">下载源码</div><!-- 安卓源码地址 --><div class="github-url-and">//mapopen-website-wiki.bj.bcebos.com/demos/BaiduMapSDKExample.zip</div></div><div class="wrap_table"><div class="table_nav"><div class="left-icon"></div><div>核心接口</div></div><div class="table_wrap"><div class="table_wrap_title"><div>类</div><div>接口</div><div>描述</div></div><!-- 表格接口,可有多个 --><div class="table_wrap_con"><div class="table_wrap_w"><div><div class="table-wrap-className">RoutePlanSearch</div></div><div><div>newInstance()</div></div><div><div>创建路线规划检索实例</div></div></div><!-- --><div class="table_wrap_w"><div><div class="table-wrap-className">RoutePlanSearch</div></div><div><div>setOnGetRoutePlanResultListener(OnGetRoutePlanResultListener listener)</div></div><div><div>设置路线规划检索监听器</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">RoutePlanSearch</div></div><div><div>bikingSearch(BikingRoutePlanOption option)</div></div><div><div>发起骑行路线规划检索请求</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">RoutePlanSearch</div></div><div><div>destory()</div></div><div><div>释放路线规划检索实例</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">OnGetRoutePlanResultListener</div></div><div><div>onGetBikingRouteResult(BikingRouteResult bikingRouteResult)</div></div><div><div>骑行路线规划的结果回调函数</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">PlanNode</div></div><div><div>withCityNameAndPlaceName(String cityName, String placeName)</div></div><div><div>路线规划起终点参数</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">BikingRoutePlanOption</div></div><div><div>from(PlanNode startNode)</div></div><div><div>设置路线规划起点参数</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">BikingRoutePlanOption</div></div><div><div>to(PlanNode endNode)</div></div><div><div>设置路线规划终点参数</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">BikingRoutePlanOption</div></div><div><div>ridingType(int type)</div></div><div><div>设置骑行路线规划类型</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">BikingRouteOverlay</div></div><div><div>setData(BikingRouteLine routeLine)</div></div><div><div>设置骑行路线规划结果数据</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">BikingRouteOverlay</div></div><div><div>addToMap()</div></div><div><div>添加骑行路线添加到地图上</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">BikingRouteOverlay</div></div><div><div>zoomToSpanPaddingBounds(int paddingLeft, int paddingTop, int paddingRight, int paddingRight)</div></div><div><div>将骑行路线调整到地图显示的最佳视野范围内</div></div></div></div></div></div></div></div><div class="pre-nav"><div class="left-icon"></div><div>核心代码</div></div><div class="pre-nav"><div>1.骑行路线规划结果解析</div></div><div class="pre-wrap"><div class="pre-wrap-nav"><div>JAVA</div></div><!-- 安卓示例代码位置 --><div class="pre-wrap-w pre-wrap-w-and"><pre class="prettyprint prettyprinted pre-and">/** | |
− | + | ||
− | + | ||
− | + | ||
− | </div> | + | |
− | <div class="demos_wrap"> | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | /** | + | |
* 设置路线数据。 | * 设置路线数据。 | ||
* | * | ||
第240行: | 第16行: | ||
List<OverlayOptions> overlayList = new ArrayList<OverlayOptions>(); | List<OverlayOptions> overlayList = new ArrayList<OverlayOptions>(); | ||
− | if (mRouteLine.getAllStep() != null | + | if (mRouteLine.getAllStep()!= null |
&& mRouteLine.getAllStep().size() > 0) { | && mRouteLine.getAllStep().size() > 0) { | ||
− | for (BikingRouteLine.BikingStep step : mRouteLine.getAllStep()) { | + | for (BikingRouteLine.BikingStep step: mRouteLine.getAllStep()) { |
Bundle b = new Bundle(); | Bundle b = new Bundle(); | ||
b.putInt("index", mRouteLine.getAllStep().indexOf(step)); | b.putInt("index", mRouteLine.getAllStep().indexOf(step)); | ||
− | if (step.getEntrance() != null) { | + | if (step.getEntrance()!= null) { |
overlayList.add((new MarkerOptions()).position(step.getEntrance().getLocation()) | overlayList.add((new MarkerOptions()).position(step.getEntrance().getLocation()) | ||
.rotate((360 - step.getDirection())).zIndex(10).anchor(0.5f, 0.5f) | .rotate((360 - step.getDirection())).zIndex(10).anchor(0.5f, 0.5f) | ||
第255行: | 第31行: | ||
if (mRouteLine.getAllStep().indexOf(step) == (mRouteLine | if (mRouteLine.getAllStep().indexOf(step) == (mRouteLine | ||
.getAllStep().size() - 1) | .getAllStep().size() - 1) | ||
− | && step.getExit() != null) { | + | && step.getExit()!= null) { |
overlayList.add((new MarkerOptions()).position(step.getExit().getLocation()) | overlayList.add((new MarkerOptions()).position(step.getExit().getLocation()) | ||
.anchor(0.5f, 0.5f).zIndex(10) | .anchor(0.5f, 0.5f).zIndex(10) | ||
第264行: | 第40行: | ||
} | } | ||
// starting | // starting | ||
− | if (mRouteLine.getStarting() != null) { | + | if (mRouteLine.getStarting()!= null) { |
overlayList.add((new MarkerOptions()).position(mRouteLine.getStarting().getLocation()) | overlayList.add((new MarkerOptions()).position(mRouteLine.getStarting().getLocation()) | ||
− | .icon(getStartMarker() != null ? getStartMarker() | + | .icon(getStartMarker()!= null? getStartMarker() |
− | + | : BitmapDescriptorFactory.fromAssetWithDpi("Icon_start.png")) | |
.zIndex(10)); | .zIndex(10)); | ||
} | } | ||
// terminal | // terminal | ||
− | if (mRouteLine.getTerminal() != null) { | + | if (mRouteLine.getTerminal()!= null) { |
overlayList.add((new MarkerOptions()).position(mRouteLine.getTerminal().getLocation()) | overlayList.add((new MarkerOptions()).position(mRouteLine.getTerminal().getLocation()) | ||
− | .icon(getTerminalMarker() != null ? getTerminalMarker() | + | .icon(getTerminalMarker()!= null? getTerminalMarker() |
− | + | : BitmapDescriptorFactory.fromAssetWithDpi("Icon_end.png")) | |
.zIndex(10)); | .zIndex(10)); | ||
} | } | ||
// poly line list | // poly line list | ||
− | if (mRouteLine.getAllStep() != null | + | if (mRouteLine.getAllStep()!= null |
&& mRouteLine.getAllStep().size() > 0) { | && mRouteLine.getAllStep().size() > 0) { | ||
LatLng lastStepLastPoint = null; | LatLng lastStepLastPoint = null; | ||
− | for (BikingRouteLine.BikingStep step : mRouteLine.getAllStep()) { | + | for (BikingRouteLine.BikingStep step: mRouteLine.getAllStep()) { |
List<LatLng> watPoints = step.getWayPoints(); | List<LatLng> watPoints = step.getWayPoints(); | ||
− | if (watPoints != null) { | + | if (watPoints!= null) { |
List<LatLng> points = new ArrayList<LatLng>(); | List<LatLng> points = new ArrayList<LatLng>(); | ||
− | if (lastStepLastPoint != null) { | + | if (lastStepLastPoint!= null) { |
points.add(lastStepLastPoint); | points.add(lastStepLastPoint); | ||
} | } | ||
第307行: | 第83行: | ||
</pre> | </pre> | ||
− | + | <div class="pre-btn"><div class="pre-btn-copy-and">复制</div><div class="pre-btn-cb-and">深色</div></div><div class="success">复制成功</div></div></div><div class="pre-nav"><div>2.将骑行路线添加到地图上</div></div><div class="pre-wrap"><div class="pre-wrap-nav"><div>JAVA</div></div><!-- 安卓示例代码位置 --><div class="pre-wrap-w pre-wrap-w-and"><pre class="prettyprint prettyprinted pre-and">/** | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | /** | + | |
* 将骑行路线添加到地图上 | * 将骑行路线添加到地图上 | ||
*/ | */ | ||
第333行: | 第92行: | ||
List<OverlayOptions> overlayOptions = getOverlayOptions(); | List<OverlayOptions> overlayOptions = getOverlayOptions(); | ||
− | if (overlayOptions != null) { | + | if (overlayOptions!= null) { |
mOverlayOptionList.addAll(getOverlayOptions()); | mOverlayOptionList.addAll(getOverlayOptions()); | ||
} | } | ||
− | for (OverlayOptions option : mOverlayOptionList) { | + | for (OverlayOptions option: mOverlayOptionList) { |
mBaiduMap.addOverlay(option) | mBaiduMap.addOverlay(option) | ||
} | } | ||
} | } | ||
</pre> | </pre> | ||
− | + | <div class="pre-btn"><div class="pre-btn-copy-and">复制</div><div class="pre-btn-cb-and">深色</div></div><div class="success">复制成功</div></div></div><div class="pre-nav"><div>3.将骑行路线调整到地图显示的最佳视野范围内</div></div><div class="pre-wrap"><div class="pre-wrap-nav"><div>JAVA</div></div><!-- 安卓示例代码位置 --><div class="pre-wrap-w pre-wrap-w-and"><pre class="prettyprint prettyprinted pre-and">/** | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | /** | + | |
* 将骑行路线调整到地图显示的最佳视野范围内 | * 将骑行路线调整到地图显示的最佳视野范围内 | ||
*/ | */ | ||
第369行: | 第111行: | ||
if (mOverlayList.size() > 0) { | if (mOverlayList.size() > 0) { | ||
LatLngBounds.Builder builder = new LatLngBounds.Builder(); | LatLngBounds.Builder builder = new LatLngBounds.Builder(); | ||
− | for (Overlay overlay : mOverlayList) { | + | for (Overlay overlay: mOverlayList) { |
// polyline 中的点可能太多,只按marker 缩放 | // polyline 中的点可能太多,只按marker 缩放 | ||
if (overlay instanceof Marker) { | if (overlay instanceof Marker) { | ||
第383行: | 第125行: | ||
</pre> | </pre> | ||
− | + | <div class="pre-btn"><div class="pre-btn-copy-and">复制</div><div class="pre-btn-cb-and">深色</div></div><div class="success">复制成功</div></div></div><div class="more-nav"><div class="left-icon"></div><div>更多功能</div></div><div class="more-wrap"><!-- 安卓更多功能下选项 --><!-- 点标记动画|/index.php?title=test --><div><div class="point"></div><div class="documentA">骑行导航|/index.php?title=androidsdk/guide/navigation/bikenavi</div></div></div></div><div class="ios-wrap wrap" style="display: none;"><div class="wrap-wp"><div class="wrap_left"><div class="left-video"><div class="img-bg-ios-sh"></div><div class="phone-ios"><div class="video-wrap infor"><div class="video-control"></div><!-- ios视频位置 --><pre>//mapopen-website-wiki.bj.bcebos.com/demos/iosVideos/iOS骑行路线规划.mov</pre> | |
− | + | </div><div class="video-icon-ios"><div class="play play-ios"></div><div class="stop stop-ios"></div></div></div><div class="progressWrap-hide-ios"></div><div id="videoControls-ios"><div id="progressWrap-ios"><div id="playProgress-ios"></div></div></div></div><div class="left-qrCode iosqrCode"><!-- ios二维码位置 --><div class="qrCode-ios">1590746640|//mapopen-website-wiki.bj.bcebos.com/demos/ioscodes/骑行路线规划@1xios.png</div><div>扫码体验</div></div></div><div class="wrap_right"><div class="wrap_right_nav"><div class="wrap_right_nav_l"><div>使用产品</div><div><!-- IOS使用产品下选项,可有多个 --><div class="documentA">iOS地图SDK|/index.php?title=iossdk</div><!-- --><div>></div><div class="documentA">骑行路线规划|/index.php?title=iossdk/guide/route/bike</div></div></div><div class="wrap_right_nav_r">下载源码</div><!-- IOS源码地址 --><div class="github-url-ios">//mapopen-website-wiki.bj.bcebos.com/BaiduMapSDKDemo.zip</div></div><div class="wrap_table"><div class="table_nav"><div class="left-icon"></div><div>核心接口</div></div><div class="table_wrap"><div class="table_wrap_title"><div>类</div><div>接口</div><div>描述</div></div><!-- ios表格接口内容,可有多个 --><!-- 表格接口,可有多个 --><div class="table_wrap_con"><div class="table_wrap_w"><div><div class="table-wrap-className">BMKRouteSearch</div></div><div><div>- (instancetype)init;</div></div><div><div>创建路线规划检索实例</div></div></div><!-- --><div class="table_wrap_w"><div><div class="table-wrap-className">BMKRouteSearch</div></div><div><div>id<BMKRouteSearchDelegate> delegate;</div></div><div><div>设置路线规划检索监听器</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">BMKRouteSearch</div></div><div><div>- (BOOL)ridingSearch:(BMKRidingRoutePlanOption *)ridingRoutePlanOption;</div></div><div><div>发起骑行路线规划检索请求</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">BMKRouteSearchDelegate</div></div><div><div>- (void)onGetRidingRouteResult:(BMKRouteSearch *)searcher result:(BMKRidingRouteResult *)result errorCode:(BMKSearchErrorCode)error;</div></div><div><div>骑行路线规划的结果回调函数</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">BMKPlanNode</div></div><div><div>NSString *cityName;</div></div><div><div>路线规划起终点城市参数</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">BMKPlanNode</div></div><div><div>NSString *name;</div></div><div><div>路线规划起终点名称参数</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">BMKWalkingRoutePlanOption</div></div><div><div>BMKPlanNode *from;</div></div><div><div>设置路线规划起点参数</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">BMKWalkingRoutePlanOption</div></div><div><div>BMKPlanNode *to;</div></div><div><div>设置路线规划终点参数</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">BMKRidingRoutePlanOption</div></div><div><div>NSInteger ridingType;</div></div><div><div>设置骑行类型(0:普通骑行,1:电动车骑行),默认是普通骑行</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">BMKPolyline</div></div><div><div>+ (BMKPolyline *)polylineWithPoints:(BMKMapPoint *)points count:(NSUInteger)count;</div></div><div><div>设置骑行路线规划点数据</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">BMKMapView</div></div><div><div>- (void)addOverlay:(id <BMKOverlay>)overlay;</div></div><div><div>添加骑行路线添加到地图上</div></div></div><div class="table_wrap_w"><div><div class="table-wrap-className">BMKBikeRoutePlanViewController</div></div><div><div>- (void)mapViewFitPolyline:(BMKPolyline *)polyline;</div></div><div><div>将骑行路线调整到地图显示的最佳视野范围内</div></div></div></div></div></div></div></div><div class="pre-nav"><div class="left-icon"></div><div>核心代码</div></div><div class="pre-nav"><div>1.骑行路线规划结果解析</div></div><div class="pre-wrap"><div class="pre-wrap-nav"><div>Objective-C</div></div><div class="pre-wrap-w pre-wrap-w-ios code_container"><!-- ios示例代码位置 --><pre class="prettyprint prettyprinted pre-ios">NSMutableArray *tempArray = [NSMutableArray array]; | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | NSMutableArray *tempArray = [NSMutableArray array]; | + | |
//+polylineWithPoints: count:坐标点的个数 | //+polylineWithPoints: count:坐标点的个数 | ||
__block NSUInteger pointCount = 0; | __block NSUInteger pointCount = 0; | ||
第625行: | 第139行: | ||
model.instruction = step.instruction; | model.instruction = step.instruction; | ||
NSString *instruction = step.instruction; | NSString *instruction = step.instruction; | ||
− | NSDictionary *attrs = @{NSFontAttributeName : [UIFont fontWithName:@"PingFangSC-Regular" size:16 * widthScale]}; | + | NSDictionary *attrs = @{NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Regular" size:16 * widthScale]}; |
CGSize size = CGSizeMake(KScreenWidth - 86 * widthScale, MAXFLOAT); | CGSize size = CGSizeMake(KScreenWidth - 86 * widthScale, MAXFLOAT); | ||
CGSize actualsize = [instruction boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size; | CGSize actualsize = [instruction boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size; | ||
第649行: | 第163行: | ||
}]; | }]; | ||
</pre> | </pre> | ||
− | + | <div class="pre-btn"><div class="pre-btn-copy-ios">复制</div><div class="pre-btn-cb-ios">深色</div></div><div class="success">复制成功</div></div></div><div class="pre-nav"><div>2.将骑行路线和起终点添加到地图上</div></div><div class="pre-wrap"><div class="pre-wrap-nav"><div>Objective-C</div></div><div class="pre-wrap-w pre-wrap-w-ios code_container"><!-- ios示例代码位置 --><pre class="prettyprint prettyprinted pre-ios">//设置起点 | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | //设置起点 | + | |
CLLocationCoordinate2D start = BMKCoordinateForMapPoint(points[0]); | CLLocationCoordinate2D start = BMKCoordinateForMapPoint(points[0]); | ||
_startAnnotation = [[BMKPointAnnotation alloc] init]; | _startAnnotation = [[BMKPointAnnotation alloc] init]; | ||
第688行: | 第184行: | ||
</pre> | </pre> | ||
− | + | <div class="pre-btn"><div class="pre-btn-copy-ios">复制</div><div class="pre-btn-cb-ios">深色</div></div><div class="success">复制成功</div></div></div><div class="pre-nav"><div>3.将骑行路线调整到地图显示的最佳视野范围内</div></div><div class="pre-wrap"><div class="pre-wrap-nav"><div>Objective-C</div></div><div class="pre-wrap-w pre-wrap-w-ios code_container"><!-- ios示例代码位置 --><pre class="prettyprint prettyprinted pre-ios">//根据polyline设置地图范围 | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | //根据polyline设置地图范围 | + | |
- (void)mapViewFitPolyline:(BMKPolyline *)polyline { | - (void)mapViewFitPolyline:(BMKPolyline *)polyline { | ||
double leftTop_x, leftTop_y, rightBottom_x, rightBottom_y; | double leftTop_x, leftTop_y, rightBottom_x, rightBottom_y; | ||
第741行: | 第219行: | ||
</pre> | </pre> | ||
− | + | <div class="pre-btn"><div class="pre-btn-copy-ios">复制</div><div class="pre-btn-cb-ios">深色</div></div><div class="success">复制成功</div></div></div><div class="more-nav"><div class="left-icon"></div><div>更多功能</div></div><div class="more-wrap"><!-- IOS更多功能下选项 --><!-- 点标记动画|/index.php?title=test --><div><div class="point"></div><div class="documentA">骑行导航|/index.php?title=iossdk/guide/navigation/bike</div></div></div></div></div> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | </div> | + |
2022年2月25日 (五) 17:30的最后版本
骑行路线规划
功能场景
物流快递、出行、O2O等APP中常使用骑行路线规划功能,展示小车到目的地的路线、时间、里程信息等。
Android
iOS
//mapopen-website-wiki.bj.bcebos.com/demos/AndroidVideos/SVID_20200530_210144_1.mp4
1590746640|//mapopen-website-wiki.bj.bcebos.com/demos/newqrcodes/骑行路线规划.png
扫码体验
使用产品
Android地图SDK|/index.php?title=androidsdk
>
骑行路线规划|/index.php?title=androidsdk/guide/route/bike
下载源码
//mapopen-website-wiki.bj.bcebos.com/demos/BaiduMapSDKExample.zip
核心接口
类
接口
描述
RoutePlanSearch
newInstance()
创建路线规划检索实例
RoutePlanSearch
setOnGetRoutePlanResultListener(OnGetRoutePlanResultListener listener)
设置路线规划检索监听器
RoutePlanSearch
bikingSearch(BikingRoutePlanOption option)
发起骑行路线规划检索请求
RoutePlanSearch
destory()
释放路线规划检索实例
OnGetRoutePlanResultListener
onGetBikingRouteResult(BikingRouteResult bikingRouteResult)
骑行路线规划的结果回调函数
PlanNode
withCityNameAndPlaceName(String cityName, String placeName)
路线规划起终点参数
BikingRoutePlanOption
from(PlanNode startNode)
设置路线规划起点参数
BikingRoutePlanOption
to(PlanNode endNode)
设置路线规划终点参数
BikingRoutePlanOption
ridingType(int type)
设置骑行路线规划类型
BikingRouteOverlay
setData(BikingRouteLine routeLine)
设置骑行路线规划结果数据
BikingRouteOverlay
addToMap()
添加骑行路线添加到地图上
BikingRouteOverlay
zoomToSpanPaddingBounds(int paddingLeft, int paddingTop, int paddingRight, int paddingRight)
将骑行路线调整到地图显示的最佳视野范围内
核心代码
1.骑行路线规划结果解析
JAVA
/** * 设置路线数据。 * * @param line 路线数据 */ public void setData(BikingRouteLine line) { mRouteLine = line; } @Override public final List<OverlayOptions> getOverlayOptions() { if (mRouteLine == null) { return null; } List<OverlayOptions> overlayList = new ArrayList<OverlayOptions>(); if (mRouteLine.getAllStep()!= null && mRouteLine.getAllStep().size() > 0) { for (BikingRouteLine.BikingStep step: mRouteLine.getAllStep()) { Bundle b = new Bundle(); b.putInt("index", mRouteLine.getAllStep().indexOf(step)); if (step.getEntrance()!= null) { overlayList.add((new MarkerOptions()).position(step.getEntrance().getLocation()) .rotate((360 - step.getDirection())).zIndex(10).anchor(0.5f, 0.5f) .extraInfo(b) .icon(BitmapDescriptorFactory.fromAssetWithDpi("Icon_line_node.png"))); } // 最后路段绘制出口点 if (mRouteLine.getAllStep().indexOf(step) == (mRouteLine .getAllStep().size() - 1) && step.getExit()!= null) { overlayList.add((new MarkerOptions()).position(step.getExit().getLocation()) .anchor(0.5f, 0.5f).zIndex(10) .icon(BitmapDescriptorFactory.fromAssetWithDpi("Icon_line_node.png"))); } } } // starting if (mRouteLine.getStarting()!= null) { overlayList.add((new MarkerOptions()).position(mRouteLine.getStarting().getLocation()) .icon(getStartMarker()!= null? getStartMarker() : BitmapDescriptorFactory.fromAssetWithDpi("Icon_start.png")) .zIndex(10)); } // terminal if (mRouteLine.getTerminal()!= null) { overlayList.add((new MarkerOptions()).position(mRouteLine.getTerminal().getLocation()) .icon(getTerminalMarker()!= null? getTerminalMarker() : BitmapDescriptorFactory.fromAssetWithDpi("Icon_end.png")) .zIndex(10)); } // poly line list if (mRouteLine.getAllStep()!= null && mRouteLine.getAllStep().size() > 0) { LatLng lastStepLastPoint = null; for (BikingRouteLine.BikingStep step: mRouteLine.getAllStep()) { List<LatLng> watPoints = step.getWayPoints(); if (watPoints!= null) { List<LatLng> points = new ArrayList<LatLng>(); if (lastStepLastPoint!= null) { points.add(lastStepLastPoint); } points.addAll(watPoints); overlayList.add(new PolylineOptions().points(points).width(18).dottedLine(true) .customTexture(getBikeRoadCustomTexture()).zIndex(0)); lastStepLastPoint = watPoints.get(watPoints.size() - 1); } } } return overlayList; } public BitmapDescriptor getBikeRoadCustomTexture() { return BitmapDescriptorFactory.fromAsset("Icon_road_blue_arrow.png"); }
复制
深色
复制成功
2.将骑行路线添加到地图上
JAVA
/** * 将骑行路线添加到地图上 */ public final void addToMap() { if (mBaiduMap == null) { return; } List<OverlayOptions> overlayOptions = getOverlayOptions(); if (overlayOptions!= null) { mOverlayOptionList.addAll(getOverlayOptions()); } for (OverlayOptions option: mOverlayOptionList) { mBaiduMap.addOverlay(option) } }
复制
深色
复制成功
3.将骑行路线调整到地图显示的最佳视野范围内
JAVA
/** * 将骑行路线调整到地图显示的最佳视野范围内 */ public void zoomToSpanPaddingBounds(int paddingLeft, int paddingTop, int paddingRight, int paddingBottom) { if (mBaiduMap == null) { return; } if (mOverlayList.size() > 0) { LatLngBounds.Builder builder = new LatLngBounds.Builder(); for (Overlay overlay: mOverlayList) { // polyline 中的点可能太多,只按marker 缩放 if (overlay instanceof Marker) { builder.include(((Marker) overlay).getPosition()); } } mBaiduMap.setMapStatus(MapStatusUpdateFactory .newLatLngBounds(builder.build(), paddingLeft, paddingTop, paddingRight, paddingBottom)); } }
复制
深色
复制成功
更多功能
骑行导航|/index.php?title=androidsdk/guide/navigation/bikenavi