2
我正在使用GWT(版本2.61)和gwt-maps(版本3.8.0)嘗試顯示Google地圖GWT。GWT Google地圖:setCenter:不是LatLng或LatLngLiteral:屬性lat:不是數字
基礎知識似乎工作,但現在我試圖運行gwt-maps zip附帶的CitySimple示例。 Here它是直接JavaScript,但我試圖通過GWT來完成。
然而,當我運行示例,我在啓動時出現以下錯誤:
com.google.gwt.core.client.JavaScriptException: (InvalidValueError) @com.google.maps.gwt.client.Circle::create(Lcom/google/maps/gwt/client/CircleOptions;)([JavaScript object(17)]): setCenter: not a LatLng or LatLngLiteral: in property lat: not a number
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:249)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:576)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:284)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.maps.gwt.client.Circle$.create(Circle.java)
at com.test.client.GwtTest.renderMap(GwtTest.java:80)
的地圖上顯示了,但沒有一個城市圈的出現。它似乎認爲我的LatLng類型中的緯度值不是一個數字,這在GWT中是不可能的,因爲Java將只有取雙倍值。
這裏是GWT代碼我運行:
package com.test.client;
import java.util.HashMap;
import com.google.gwt.ajaxloader.client.AjaxLoader;
import com.google.gwt.ajaxloader.client.AjaxLoader.AjaxLoaderOptions;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.dom.client.Document;
import com.google.maps.gwt.client.Circle;
import com.google.maps.gwt.client.CircleOptions;
import com.google.maps.gwt.client.GoogleMap;
import com.google.maps.gwt.client.LatLng;
import com.google.maps.gwt.client.MapOptions;
import com.google.maps.gwt.client.MapTypeId;
public class GwtTest implements EntryPoint {
static class City {
LatLng center;
Long population;
City(LatLng center, Long population) {
this.center = center;
this.population = population;
}
}
private static java.util.Map<String, City> citymap = new HashMap<String, City>();
static {
citymap.put("Chicago", new City(LatLng.create(41.878113, -87.629798), 2842518L));
citymap.put("New York", new City(LatLng.create(40.714352, -74.005973), 8143197L));
citymap.put("Los Angeles", new City(LatLng.create(34.052234, -118.243684), 3844829L));
}
@Override
public void onModuleLoad() {
AjaxLoaderOptions options = AjaxLoaderOptions.newInstance();
options.setOtherParms("sensor=false");
Runnable callback = new Runnable() {
public void run() {
renderMap();
}
};
AjaxLoader.loadApi("maps", "3", callback, options);
}
public static void renderMap() {
MapOptions mapOpts = MapOptions.create();
mapOpts.setZoom(4);
mapOpts.setCenter(LatLng.create(37.09024, -95.712891));
mapOpts.setMapTypeId(MapTypeId.TERRAIN);
GoogleMap map = GoogleMap.create(Document.get().getElementById("map_canvas"), mapOpts);
for (String cityName : citymap.keySet()) {
System.out.println("City: " + cityName);
City city = citymap.get(cityName);
// Construct the circle for each value in citymap. Scale population by 20.
CircleOptions populationOptions = CircleOptions.create();
populationOptions.setStrokeColor("#ff0000");
populationOptions.setStrokeOpacity(0.8);
populationOptions.setStrokeWeight(2);
populationOptions.setFillColor("#ff0000");
populationOptions.setFillOpacity(0.35);
populationOptions.setMap(map);
System.out.println("Lat: " + city.center.lat());
System.out.println("Lng: " + city.center.lng());
populationOptions.setCenter(city.center);
populationOptions.setRadius(city.population/20);
Circle.create(populationOptions);
}
}
}
正如你可以看到,所有的經緯度值對他們的拉特和LNGS數字,所以這個錯誤沒有任何意義,我。
爲了完整起見,這裏是我的html文件:
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="GwtTest.css">
<title>GWT Test</title>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" language="javascript"
src="gwttest/gwttest.nocache.js"></script>
</head>
<body>
<p>Testing</p>
<div style="width:500px; height:500px">
<div id="map_canvas" style="width: 100%; height: 100%;">Map is loading...</div>
</div>
</body>
</html>
,這裏是我的GWT模塊XML文件:
<?xml version="1.0" encoding="UTF-8"?>
<!--
When updating your version of GWT, you should also update this DTD reference,
so that your app can take advantage of the latest GWT module capabilities.
-->
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.6.1//EN"
"file:///C:/Users/kworkman/Desktop/gwt-2.6.1/gwt-module.dtd">
<module rename-to='gwttest'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<inherits name="com.google.maps.gwt.GoogleMaps" />
<inherits name="com.google.gwt.ajaxloader.AjaxLoader" />
<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<inherits name='com.google.gwt.user.theme.clean.Clean'/>
<!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
<!-- Other module inherits -->
<!-- Specify the app entry point class. -->
<entry-point class='com.test.client.GwtTest'/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
<!-- allow Super Dev Mode -->
<add-linker name="xsiframe"/>
</module>
任何人都可以看到什麼我做錯了嗎?我還是GWT的全新人物,所以如果我在做一些愚蠢的事情時我不會感到震驚,但是這個錯誤似乎與代碼直接矛盾,所以我有點不知所措。
我已經使用了這個錯誤,但是我看到的每個問題都是由人們通過字符串而不是數字傳遞給LatLng類型造成的,而我並沒有這樣做。
您可以下載地圖api兩次:一次在您的html文件(