【发布时间】:2023-04-06 13:09:01
【问题描述】:
我想在 Google Maps API v3, GWT 2.5.1 中绘制五条不同的路线。我初始化了一个在这个类中设置其DirectionDisplay 和DirectionsRequest 的路由。
当我开始我的网络项目时,有时只显示我的第一条路线,有时会显示全部五个,所以我决定制作一个System.out.print(m);。
结果:
01234 -> 符合预期,显示所有路线
10234 -> 错误,仅显示第一条路线。
为什么 Google 会在我的第一个请求之前处理我的第二个请求?我尝试使用Thread.sleep(1000) 来确保我的请求有时间按顺序返回,还有Timer/TimerTasks,没有成功。有什么想法吗?
DirectionsService o = DirectionsService.newInstance();
for (Integer i = 0; i < 4; i++) { //routes.size()
final int m = i;
final Route route = new Route("Route " + i.toString());
route.initRoute(m, getRoutingPresenter(), adressData, addressIndex);
//here i initialize the DirectionsRequests and its Displays, which
//i set in this class after execution.
o.route(directionsRequest, new DirectionsResultHandler() {
@Override
public void onCallback(DirectionsResult result,DirectionsStatus status) {
if (status == DirectionsStatus.OK) {
System.out.print(m);
...
}
}
);
}
}
【问题讨论】:
标签: java gwt google-maps-api-3