BNRoutePlanInfos routePlaneInfos = BaiduNaviManagerFactory.getRoutePlanManager() .getRoutePlanInfo(); 这段代码为空应该怎么写
时间: 2023-11-28 08:49:50 浏览: 39
如果该段代码返回的是空值,你可以在获取 `BNRoutePlanInfos` 对象之前先进行路线规划操作。例如:
```
// 创建起点和终点
BNaviPoint startPoint = new BNaviPoint(startLng, startLat, "起点", BNaviPoint.CoordinateType.BD09LL);
BNaviPoint endPoint = new BNaviPoint(endLng, endLat, "终点", BNaviPoint.CoordinateType.BD09LL);
// 创建路线规划参数
BaiduNaviManagerFactory.getRoutePlanManager().setObserver(new RoutePlanManager.RoutePlanObserver() {
@Override
public void onRoutePlanStart() {
// 路线规划开始
}
@Override
public void onRoutePlanSuccess() {
// 路线规划成功,可以获取路线规划信息了
BNRoutePlanInfos routePlanInfos = BaiduNaviManagerFactory.getRoutePlanManager().getRoutePlanInfo();
// ...
}
@Override
public void onRoutePlanFail(BaiduNaviManager.RoutePlanFailCode routePlanFailCode) {
// 路线规划失败
}
@Override
public void onRoutePlanCanceled() {
// 路线规划取消
}
});
// 进行路线规划
BaiduNaviManagerFactory.getRoutePlanManager().routePlanToNavi(startPoint, endPoint, null, BaiduNaviManager.RoutePlanPreference.ROUTE_PLAN_MOD_RECOMMEND, false, null);
```
在上述代码中,我们先创建了起点和终点,然后通过 `setObserver()` 方法设置了路线规划回调监听器,最后调用 `routePlanToNavi()` 方法进行路线规划。当路线规划成功后,我们就可以通过 `getRoutePlanInfo()` 方法获取路线规划信息了。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)