我正在尝试在我的 javafx 程序中使用 gmapsfx。
我的代码是这样的:
@Override
public void initialize(URL url, ResourceBundle rb) {
mapView = new GoogleMapView();
mapView.addMapInializedListener(this);
}
@Override
public void mapInitialized() {
MapOptions options = new MapOptions();
options
.center(new LatLong(40.7127, -74.0059))
.mapType(MapTypeIdEnum.ROADMAP)
.zoom(12);
map = mapView.createMap(options);
mapView.setKey("");
showMarker(40.748433, -73.985656, "https://upload.wikimedia.org/wikipedia/commons/thumb/1/13/Disc_Plain_red.svg/32px-Disc_Plain_red.svg.png");
showMarker(40.713, -74.0135, "https://upload.wikimedia.org/wikipedia/commons/thumb/0/02/Disc_Plain_blue.svg/32px-Disc_Plain_blue.svg.png");
}
/**
* Adds a marker to the map.
*/
public void showMarker(double lat, double lng, String iconPath) {
MarkerOptions options = new MarkerOptions();
options
.icon(iconPath)
.position(new LatLong(lat, lng));
Marker marker = new Marker(options);
map.addMarker(marker);
}
这是我遇到的错误。我想我只是错过了一些东西..............................................................
Exception in thread "JavaFX Application Thread" netscape.javascript.JSException: ReferenceError: Can't find variable: loadMapLibrary
at com.sun.webkit.dom.JSObject.fwkMakeException(JSObject.java:146)
at com.sun.webkit.WebPage.twkExecuteScript(Native Method)
Exception in thread "JavaFX Application Thread" netscape.javascript.JSException: ReferenceError: Can't find variable: google
at com.sun.webkit.dom.JSObject.fwkMakeException(JSObject.java:146)
at com.sun.webkit.WebPage.twkExecuteScript(Native Method)
at com.sun.webkit.WebPage.executeScript(WebPage.java:1509)
请您参考如下方法:
我必须在 Controller 的初始化方法中设置键mapView.setKey("");
,然后 map 加载没有错误。