我正在尝试使用 JSNI 在应用程序中显示谷歌地图。我已经在我的 index.html 页面中定义了脚本。
这是 uibinder 的定义(摘录到要点):
<g:HTMLPanel ui:field="mapboxV3ContentPanel">
<!-- div for display of the actual map -->
<div id="map"><!-- --></div>
</g:HTMLPanel>
这是 initializeMap() 原生函数:
private native void initializeMap() /*-{
var latLng = new $wnd.google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
zoom: 8,
center: latLng,
mapTypeId: $wnd.google.maps.MapTypeId.ROADMAP
};
var mapDiv = $doc.getElementById('map');
if (mapDiv==null) {
alert("MapDiv is null!");
}
var map = new $wnd.google.maps.Map(mapDiv, mapOptions);
}-*/;
不幸的是,mapDiv 为空。有什么帮助吗?
我知道 gwt-maps 和 gwt-maps-v3 项目。第一个只支持 API 的 v2,而 gwt-maps-v3 对我不起作用,因此是 JSNI 方法。