我正在尝试在路线沿线的地图上显示实时交通信息。但是,它似乎没有出现在我选择的路线上,但它出现在其他地方。有人可以阐明这个问题吗?我还附上了我的应用程序的屏幕截图。截图 1 截图 2
private void createRoute(RouteOptions.TransportMode transportMode, GeoCoordinate startCoodinate, GeoCoordinate endCoodinate) {
CoreRouter coreRouter = new CoreRouter();
RoutePlan routePlan = new RoutePlan();
RouteWaypoint startPoint = new RouteWaypoint(startCoodinate);
RouteWaypoint destination = new RouteWaypoint(endCoodinate);
routePlan.addWaypoint(startPoint);
routePlan.addWaypoint(destination);
RouteOptions routeOptions = new RouteOptions();
routeOptions.setTransportMode(transportMode);
routeOptions.setHighwaysAllowed(false);
routeOptions.setRouteType(RouteOptions.Type.SHORTEST);
routeOptions.setRouteCount(1);
routePlan.setRouteOptions(routeOptions);
trafficUpdater = TrafficUpdater.getInstance();
trafficUpdater.enableUpdate(true);
TrafficUpdater.GetEventsListener myGetEventsListener = new TrafficUpdater.GetEventsListener() {
@Override
public void onComplete(List<TrafficEvent> trafficEvent, TrafficUpdater.Error error) {
if (error == TrafficUpdater.Error.NONE) {
// how to use the callback trafficEvent to affect m_mapRoute ?????
} else {
}
}
};
TrafficUpdater.Listener myTrafficUpdaterListener = new TrafficUpdater.Listener() {
@Override
public void onStatusChanged(TrafficUpdater.RequestState requestState) {
if (requestState.equals(TrafficUpdater.RequestState.DONE)) {
trafficUpdater.getEvents(m_mapRoute.getRoute(), myGetEventsListener);
}
}
};
CoreRouter.Listener myCoreRouterListener = new CoreRouter.Listener() {
@Override
public void onProgress(int i) {
/* The calculation progress can be retrieved in this callback. */
}
@Override
public void onCalculateRouteFinished(List<RouteResult> routeResults, RoutingError routingError) {
if (routingError == RoutingError.NONE) {
if (routeResults.get(0).getRoute() != null) {
m_mapRoute = new MapRoute(routeResults.get(0).getRoute());
trafficUpdater.request(m_mapRoute.getRoute(), 100, myTrafficUpdaterListener);
m_map.addMapObject(m_mapRoute);
m_mapRoute.setRenderType(MapRoute.RenderType.SECONDARY);
GeoBoundingBox gbb = routeResults.get(0).getRoute()
.getBoundingBox();
m_map.zoomTo(gbb, Map.Animation.NONE, Map.MOVE_PRESERVE_ORIENTATION);
} else {
Toast.makeText(m_activity,
“Error:route results returned is not valid”,
Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(m_activity,
“Error:route calculation returned error code: ” + routingError,
Toast.LENGTH_LONG).show();
}
}
};
coreRouter.calculateRoute(routePlan, myCoreRouterListener);
}
我得到的信息的结果如下:
Traffic flow message.
Event Text: Traffic flow message.
Short Text: FLOW
Severity: HIGH
Affected Streets: [Norra Vallgatan]
Affected Length: 500
From Streets: [Hamngatan]
To Streets: [Slottsgatan]
Speed Limit: 17
Flow: True
Incident: False
Visible: True
Penalty: 0
HIGH
17
Norra Vallgatan
即调用 TrafficUpdater.GetEventsListener 的回调结果
编辑:我已包含以下坐标:
address =[Triangeln ],
start location =[Lat: 55.61151575555467, Long: 12.994461363051823, Alt: 0.0],
end location =[Lat: 55.59671, Long: 13.00098, Alt: 1.073741824E9]
address =[Gothenburg ],
start location =[Lat: 55.61163785303746, Long: 12.994434358214308, Alt: 0.0],
end location =[Lat: 57.70068, Long: 11.96823, Alt: 1.073741824E9]
希望有人能帮忙!