我试图在我的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)
答案 0 :(得分:0)
我必须在控制器的initialize方法中设置键mapView.setKey("");
,然后才能正确加载地图。