Google GWT - Maps API v3运行错误

时间:2012-11-28 03:07:17

标签: java javascript google-maps gwt google-maps-api-3

我目前正在java中创建一个允许我查看谷歌地图并计算距离的课程。此时我想做的就是查看地图。任何人都可以帮助我吗?

这是我的代码:

public class MapOperations{

    private GoogleMap map;

    /*Import Club's School and set center accordingly*/
    private static final LatLng WEST = LatLng.create(42.02606, -87.77194);
    private static final LatLng NORTH = LatLng.create(41.850033, -87.6500523);

    public MapOperations(){
        try{
            init(); 
        }
        catch(Exception e){
            System.out.println(e);
        }
    }

    public void init() {
        MapOptions mapOpts = MapOptions.create();
        mapOpts.setZoom(16);
        mapOpts.setCenter(WEST);

        mapOpts.setMapTypeControl(true);
        MapTypeControlOptions mapTypeCtrlOpts = MapTypeControlOptions.create();
        mapTypeCtrlOpts.setMapTypeIds(ArrayHelper.toJsArrayString(MapTypeId.ROADMAP.getValue(), MapTypeId.HYBRID.getValue()));
        mapTypeCtrlOpts.setStyle(MapTypeControlStyle.DROPDOWN_MENU);
        mapOpts.setMapTypeControlOptions(mapTypeCtrlOpts);

        mapOpts.setZoomControl(true);
        ZoomControlOptions zoomOpts = ZoomControlOptions.create();
        zoomOpts.setStyle(ZoomControlStyle.SMALL);
        mapOpts.setZoomControlOptions(zoomOpts);

        mapOpts.setMapTypeId(MapTypeId.ROADMAP);
        map = GoogleMap.create(Document.get().getElementById("map_canvas"), mapOpts);

        Button btn = new Button("Reset Center", new ClickHandler() {
            public void onClick(ClickEvent event) {
                map.setCenter(WEST);
                map.setZoom(16);
            }
        });

        // Add button to the root panel. (register it on the GWT side)
        RootPanel.get().add(btn);

        // Add button as a map control.
        map.getControls().get(
                new Double(ControlPosition.TOP_RIGHT.getValue()).intValue()).push(
                        btn.getElement());
    }
}

当我尝试运行我的代码时,我收到此错误:

com.google.gwt.core.client.JavaScriptException: (TypeError) @com.google.maps.gwt.client.GoogleMap::create(Lcom/google/gwt/dom/client/Node;Lcom/google/maps/gwt/client/MapOptions;)([null, JavaScript object(1433)]): Cannot read property 'offsetWidth' of null

0 个答案:

没有答案