上面的例子真的很有帮助。我正在发送我自己的一段代码,以便它也可以帮助其他人使用 GWT 2.4 开发 Google Map V3
Google Map V3 所需的罐子是 gwt-maps.jar(版本 3.8.0)。对于 Maven 构建,以下是依赖项:
<dependency>
<groupId>com.google.gwt.google-apis</groupId>
<artifactId>gwt-maps</artifactId>
<version>3.8.0</version>
</dependency>
在您的 entryPoint.gwt.xml 中写下以下内容:
<inherits name="com.google.maps.gwt.GoogleMaps" />
<script src="http://maps.google.com/maps/api/js?sensor=false" />
导入语句是:
import com.google.maps.gwt.client.MapOptions;
import com.google.maps.gwt.client.LatLng;
import com.google.maps.gwt.client.MapTypeId;
import com.google.maps.gwt.client.GoogleMap;
在 GWT 代码中,获取一个按钮并将地图加载代码写到按钮 onClick 事件中。
// This is the layout which will hold the button
final HLayout actionbuttonsLayout = new HLayout(10);
final IButton showMap = new IButton("Locate your Store");
actionbuttonsLayout.addMember(showMap);
//--- This is the layout which will hold the Map
final HLayout mapLayout = new HLayout(50);
final SimplePanel widg = new SimplePanel() ;
widg.setSize("700px", "200px");
layout.addMember(mapLayout);
mapLayout.setVisible(false);
// This is the Click Handler where the map rendering process has been written
showMap.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
MapOptions options = MapOptions.create();
options.setCenter(LatLng.create(39.509, -98.434));
options.setZoom(6);
options.setMapTypeId(MapTypeId.ROADMAP);
options.setDraggable(true);
options.setMapTypeControl(true);
options.setScaleControl(true);
options.setScrollwheel(true);
GoogleMap theMap = GoogleMap.create(widg.getElement(), options) ;
mapLayout.addMember(widg);
mapLayout.setVisible(true);
}
});