Web site and open source library development on Google App Engine (GAE) with Google Web Toolkit (GWT).

Wednesday, December 12, 2012

Google Maps v3 with GWT - Example

For a long time there was no official port of Google Maps v3 to GWT. This issue, created in June 2010, is still marked as "Started". Comments on that issue seem to indicate that the problem was due to the difficulty in generating the bindings automatically so it would be easy to keep in sync with the JavaScript API. The older v2 maps API also did not use overlay types which allows more optimised code to be generated, which v3 does.

Finally in March 2012 an official "prerelease" build was posted to the issue but never properly released. However, it is very usable and seems quite complete. One nice thing is that because it is generated automatically from the JavaScript API, it matches up very closely to the official docs. An obvious exception to this is the central class is name GoogleMap rather than Map for obvious reasons.

I'll write a little about getting started using these maps and include a little demo. The demo uses your current location (from HTML5 geo location object) and draws a circle on the map where it things you are. The map is zoomed according to how accurate the reading is so the circle should look about the same size no matter what the accuracy.

Start by getting the jar and putting it in a folder somewhere (not in your WEB-INF) and add it to your class path. Keep an eye on the downloads page in case a more recent lib is released. At this point it is for the Maps 3.8.1 API which is a already a little out of date but looking at the changelog, I can't see any great features I'd be missing.

First here is the working demo: (watch out for the dialog asking if it can use your location)