我正在尝试从gwt-map库中获取谷歌指示。 除了在onModuleLoad()中分配RootPanel之外,我还复制了SimpleDirectionsDemo.java中的大部分代码。
运行后我收到“无法加载路线:SERVER_ERROR”消息回调
Directions.load(query, opts, new DirectionsCallback() {
public void onFailure(int statusCode) {
Window.alert("Failed to load directions: Status "
+ StatusCodes.getName(statusCode) + " " + statusCode);
}
public void onSuccess(DirectionResults result) {
GWT.log("Successfully loaded directions.", null);
}
});
GWT-Map Library的API: http://gwt-google-apis.googlecode.com/svn/javadoc/maps/1.1/index.html
可以找到工作示例 http://gwt.google.com/samples/hellomaps-1.1.0/HelloMaps.html#Simple%20Directions
,这是一个在主干中找到的工作代码片段。
public SimpleDirectionsDemo() {
final Grid grid = new Grid(1, 2);
grid.setWidth("100%");
grid.getCellFormatter().setWidth(0, 0, "500px");
grid.getCellFormatter().setVerticalAlignment(0, 0,
HasVerticalAlignment.ALIGN_TOP);
grid.getCellFormatter().setWidth(0, 1, "300px");
grid.getCellFormatter().setVerticalAlignment(0, 1,
HasVerticalAlignment.ALIGN_TOP);
map = new MapWidget(LatLng.newInstance(42.351505, -71.094455), 15);
map.setHeight("480px");
grid.setWidget(0, 0, map);
DirectionsPanel directionsPanel = new DirectionsPanel();
grid.setWidget(0, 1, directionsPanel);
directionsPanel.setSize("100%", "100%");
initWidget(grid);
DirectionQueryOptions opts = new DirectionQueryOptions(map, directionsPanel);
String query = "from: 500 Memorial Dr, Cambridge, MA to: 4 Yawkey Way, Boston, MA";
Directions.load(query, opts, new DirectionsCallback() {
public void onFailure(int statusCode) {
Window.alert("Failed to load directions: Status "
+ StatusCodes.getName(statusCode) + " " + statusCode);
}
public void onSuccess(DirectionResults result) {
GWT.log("Successfully loaded directions.", null);
}
});
}
任何有谷歌地图或gwt-map经验的人都知道为什么负载会失败?
答案 0 :(得分:0)
在我结束时意识到,我决定省略DirectionsPanel。
我对DirectionQueryOptions的原始代码是
DirectionQueryOptions opts = new DirectionQueryOptions(map);
显然导致SERVER_ERROR 基于http://gwt-google-apis.googlecode.com/svn/javadoc/maps/1.1/index.html
的APIapi有一个错误,因为它给构造函数只有map作为参数。 如果您要使用gwt-map库
,则必须声明DirectionsPanel正确的代码:
DirectionQueryOptions opts = new DirectionQueryOptions(map, directionsPanel);