Thursday, January 31, 2013

JavaFX and Google Maps

There are already some examples on the Internet which demonstrates the use of a Google Maps view within a JavaFX application. They demonstrate how to control a WebView backedup google maps javascript.
One thing was always missing and that was the way back. For example how to read the current Lat Lon view position of the Google Maps view.

After some experiments I came to a simple timer based solution. The idea is that a timer function regularly polls the javascript document and parses the result.

First we take a look at the javascript code;



When the updateJavaFX() function is called the document variables (currentCenter for the position) are filled.

In the JavaFX code the following part (this part is called within an AnimationTimer) is used to retrieve the current lat lon position of the map.


Basically the trick is call the javascript document.updateJavaJX() function and then to read eg. the currentCenter javascript variable. I use the toString() function to convert it to a string and then parse it. The classcastexception is present when a different kind of map type is used eg. openstreetmap.

This all could result in the following application;










Tuesday, January 29, 2013

Fruit on Rails, 1 year


It was one year ago, when I finished my first real game.
Time flies.

http://fruitonrails.3qc.nl