2012-07-02 18 views
0

我有一個GWT應用程序,它使用Google Maps和Im試圖創建一個使用Googele的geocoder類獲取LatLng地址。Java + Google Maps API + GWT +地理編碼嘗試:在運行時獲取此異常 - 編譯良好

這是我的代碼:

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) 

林不知道這是什麼異常意味着,可以someoone幫我明白了嗎?謝謝

回答

1

您可能需要先使用Maps.loadMapsApi(...)加載Maps JS API,然後才能使用您的GWT代碼訪問地理編碼方法。

0

如果您使用模擬器,geocoder不起作用。它是一個非常大的錯誤,他們沒有修復,但解決方案是在真實設備上進行測試。希望它應該能夠工作。