Java + Google Maps API + GWT + Geocoding Try:在运行时获取此异常 - 编译正



我有一个使用谷歌地图的GWT应用程序,我试图创建一个使用Googele的地理编码器类来获取LatLng地址的方法。

这是我的代码:

Geocoder gc = new Geocoder();
    gc.getLatLng(this.testAddress, new LatLngCallback()
    {
        public void onFailure() 
        {
            System.out.println("ERROR: Could not obtain the Coordinates for address" + testAddress);
        }
        public void onSuccess(LatLng point) 
        {
            System.out.println("For Address= "+testAddress +"are Latitude: "+point.getLatitude() + "Longitude: "+ point.getLongitude());
        }
    });

它编译正常,但在运行时会引发此异常:

06:25:09.359 [ERROR] [foodvendor] Unable to load module entry point class cs310.client.Main (see associated exception for details)
com.google.gwt.core.client.JavaScriptException: (TypeError): undefined is not a function
  at     com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:248)
   at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
   at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
   at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
   at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
   at com.google.gwt.maps.client.impl.__GeocoderImplImpl.construct(__GeocoderImplImpl.java)
   at com.google.gwt.maps.client.geocode.Geocoder.<init>(Geocoder.java:41)
   at cs310.client.AshTestClass.<init>(AshTestClass.java:25)
   at cs310.client.Main.onModuleLoad(Main.java:37)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
   at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
   at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
   at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
   at java.lang.Thread.run(Thread.java:680)

不确定这个例外意味着什么,有人能帮我理解吗?谢谢

您可能需要先使用 Maps.loadMapsApi(...) 加载地图 JS API,然后 GWT 代码才能访问地理编码方法。

如果您使用的是模拟器,则地理编码器不起作用。这是一个相当大的错误,他们还没有修复,但解决方案是在真实设备上进行测试。希望它应该可以工作。

最新更新