上面的例子真的很有帮助。我发送自己的一段代码,以便它也可以帮助其他人开发带有GWT 2.4的谷歌地图V3.0
Jars对谷歌地图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语句:
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代码需要按钮并将地图加载代码写入到点击事件按钮中。
// 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);
}
});
谢谢!只是对其他人进行了一些小修改:RootLayoutPanel.get()。add(widg); – lembas
你是对的! --edited-- – Overnuts
如果我错了,请纠正我,但我认为在Google Maps v3中,不能添加'”。它不再接受文件中的'script'标签。另一种方法是稍后动态加载脚本 – Abbas