上面的例子真的很有幫助。我發送自己的一段代碼,以便它也可以幫助其他人開發帶有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