我尝试使用GWT Maps API V3 3.8.1创建演示。我的演示只显示了API版本3的谷歌地图
public class MyGoogleMap implements IsWidget {
private MapWidget map;
private static Boolean loadingApi = false;
private Timer apiLoadWaitTimer = null;
private LatLng CENTER = LatLng.newInstance(47.8, -121.4);
public MyGoogleMap(EventBus bus, String mapApiKey) {
this.eventBus = bus;
boolean sensor = true;
map = new MapWidget(MapOptions.newInstance());
// load all the libs for use in the maps
ArrayList<LoadLibrary> loadLibraries = new ArrayList<LoadApi.LoadLibrary>();
loadLibraries.add(LoadLibrary.ADSENSE);
loadLibraries.add(LoadLibrary.DRAWING);
loadLibraries.add(LoadLibrary.GEOMETRY);
loadLibraries.add(LoadLibrary.PANORAMIO);
loadLibraries.add(LoadLibrary.PLACES);
loadLibraries.add(LoadLibrary.WEATHER);
final AjaxLoaderOptions options = AjaxLoaderOptions.newInstance();
Runnable callback = new Runnable() {
@Override
public void run() {
initMap();
mapMenuProvider = new DefaultMapMenuProvider();
mapController = new MapController(map);
mapController.setMenuProvider(mapMenuProvider);
}
};
LoadApi.go(callback, loadLibraries, sensor);
}
private void initMap() {
MapOptions mapOptions = MapOptions.newInstance();
map = new MapWidget(mapOptions);
map.setCenter(CENTER);
}
}
我的.gwt.xml包含:
<inherits name='com.google.gwt.maps.Apis_Google_Maps' />
<!-- <inherits name='com.google.gwt.maps.utility.GoogleMapsUtility' /> -->
<script src="https://maps.googleapis.com/maps/api/jsv=3&key=MyGoogleAPIKey####&sensor=false"/>
我的演示成功显示了Google地图。但是,语句map.setCenter(CENTER)
会产生以下错误
setCenter: not a LatLng or LatLngLiteral: in property lat: not a number
导致此错误消息的原因是什么?
答案 0 :(得分:1)
我解决了这个问题。错误在方法initMap()中。我更正如下:
private void initMap() {
mapWidget.setSize("100%", "100%");
mapWidget.setZoom(zoomLevel);
mapWidget.setCenter(CENTER);
}