问题描述
我想开始开发JavaFX桌面应用程序,该应用程序将与Google Maps API紧密配合(如果一切顺利的话).我的上手时间比我想象的要困难得多,在这一点上,我只是在问一个人,请提供一个示例代码,这些代码可以简单地加载地图并在地图上固定几个位置.任何帮助将不胜感激.到目前为止,我能做的最好的事情就是在WebView中加载maps.google.com,这显然根本不涉及API,并且现在对我毫无用处.
I would like to start working on a JavaFX desktop app that will work heavily (if all goes well) with the Google Maps APIs. I've been having a more difficult time getting started than I thought I would, and at this point I am just asking that somebody please provide an example of some code that would simply load the map and pin a few locations on it. Any help at all would be so appreciated. The best I've been able to do so far is just load maps.google.com in a WebView, which obviously did not involve the APIs at all and really serves me no purpose right now.
推荐答案
我只是在问一个人,请提供一个示例代码,这些代码可以简单地加载地图并在地图上固定一些位置.
其中一种方法是结合使用HTML,Javascript和JavaFX.用html和javascript创建一个Google Maps实例,然后使用WebEngine类在JavaFX程序中调用URL. WebEngine 加载网页,创建其文档模型,根据需要应用样式,并在页面上运行JavaScript.之后,您将使用WebView显示google map内容,例如:
One of the ways you can do this is using a combination of HTML, Javascript and JavaFX. Create a google maps instance in html and javascript then call the URL in your JavaFX program using WebEngine class. WebEngine loads Web pages, creates their document models, applies styles as necessary, and runs JavaScript on pages. After that you'll use WebView to display the google map content like:
final WebEngine webEngine = new WebEngine(getClass().getResource("googlemap.html").toString());
final WebView webView = new WebView(webEngine);
这是一个链接示例代码的链接开始.
这篇关于如何在JavaFX桌面应用程序中使用Google Maps API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!