Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 首次加载页面时,GWT地图标记标注显示为空白_Java_Gwt_Google Maps Api 3 - Fatal编程技术网

Java 首次加载页面时,GWT地图标记标注显示为空白

Java 首次加载页面时,GWT地图标记标注显示为空白,java,gwt,google-maps-api-3,Java,Gwt,Google Maps Api 3,我是gwt新手,我有一个带有gwtmap小部件和标记位置的页面。首次加载页面时,标记标注仅显示一个X表示错误 关闭详图索引并重新打开时,将显示正确的数据 以下是gwt代码: LatLng location = new LatLng(39.565537, -79.426603); // Init the map options final MapOptions options = new MapOptions(); // Zoom level. Required options.setZo

我是
gwt
新手,我有一个带有
gwtmap
小部件和标记位置的页面。首次加载页面时,标记标注仅显示一个X表示错误

关闭详图索引并重新打开时,将显示正确的数据

以下是gwt代码:

LatLng location = new LatLng(39.565537, -79.426603);


// Init the map options
final MapOptions options = new MapOptions();
// Zoom level. Required
options.setZoom(12);
options.setCenter(location);
// Map type. Required.
options.setMapTypeId(new MapTypeId().getRoadmap());

// Enable maps drag feature. Disabled by default.
options.setDraggable(true);
// Enable and add default navigation control. Disabled by default.
options.setNavigationControl(true);
// Enable and add map type control. Disabled by default.
options.setMapTypeControl(true);

// Create map with options & set as control
final MapWidget retval = new MapWidget(options);

marker.setPosition(location);
marker.setMap(retval.getMap());

String html = "<br />Y Device location at " + loc.updateTime;
if (loc.dmTime != null) {
    html += "<br />Y Received at " + loc.dmTime;
}

infoWindow.setContent(html);
infoWindow.setPosition(location);

infoWindow.open(retval.getMap(), marker);

marker.setTitle("Whatever");

Event.addListener(marker, "click", new EventCallback() {
    @Override
    public void callback() {
        infoWindow.open(retval.getMap(), marker);
    }
});

return retval;
LatLng位置=新LatLng(39.565537,-79.426603);
//初始化映射选项
最终映射选项=新映射选项();
//缩放级别。要求的
选项。设置缩放(12);
选项。设置中心(位置);
//地图类型。必修的。
options.setMapTypeId(新的MapTypeId().getRoadmap());
//启用地图拖动功能。默认情况下禁用。
options.setDraggable(true);
//启用并添加默认导航控件。默认情况下禁用。
options.setNavigationControl(true);
//启用并添加映射类型控件。默认情况下禁用。
options.setMapTypeControl(true);
//使用选项创建地图并设置为控件(&S)
最终MapWidget retval=新的MapWidget(选项);
标记器。设置位置(位置);
marker.setMap(retval.getMap());
字符串html=“
Y设备位置在”+loc.updateTime; 如果(loc.dmTime!=null){ html+=“
在“+loc.dmTime”接收到Y; } setContent(html); 信息窗口。设置位置(位置); open(retval.getMap(),marker); marker.setTitle(“任何”); addListener(标记“单击”,新建EventCallback()){ @凌驾 公共无效回调(){ open(retval.getMap(),marker); } }); 返回返回;

当第一次加载页面时,我需要做什么才能使其正确显示?

retval
是您的
MapWidget
,并在函数结束时返回,因此我认为您稍后会在代码中执行
setWidget
。然后在显示MapWidget之前完成信息窗口的打开。。。 也许你可以试试:

Scheduler.get().scheduleDeferred(new ScheduledCommand() {                
   @Override
   public void execute() {
       infoWindow.open(retval.getMap(), marker);
   }
});

在显示地图后显示信息窗口。

运行
MapWidget。当
GoogleMap
对象完成渲染时打开
。要在
GoogleMap
对象完成时调用它,您需要使用
schedulederferred
adddleListenerOnce
,可选但最好是在
onLoad
内部:

GoogleMap retval;

@Override
protected void onLoad() {
    ...
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {                
        @Override
        public void execute() {
            retval.addIdleListenerOnce(new IdleHandler() {
                @Override
                public void handle() {
                    infoWindow.setContent(html);
                    infoWindow.setPosition(location);
                    infoWindow.open(retval.getMap(), marker);
                }
            });
        }
    });
}

我使用的是Google Map API 2.0,我没有
小部件中的
addIdleListenerOnce
,问题被标记为v3,抱歉。好的。所以我升级到了v3,但我仍然没有添加的ListenerOnce
似乎我们使用的是不同的库。请看以下链接:图书馆下载链接: