Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Google Maps GWT API - 2.2.1 - GWT 1.4, GDirections, GRoute, GStep, GTrafficOverlay, updated GGeocodeResult

133 views
Skip to first unread message

aglaforge

unread,
Jun 3, 2007, 3:04:40 PM6/3/07
to Google Web Toolkit
June 03, 2007 - Release 2.2.1

IMPORTANT NOTES:


- This release will only work with GWT 1.4


- In order to use the GDirections API, you will need to modify your
HTML where you load the Google Maps code. The change is subtle, but
important... from v=2 (before you put in the key) to v=2.x.


Old:


<script src="http://maps.google.com/maps?
file=api&amp;v=2&amp;key=ABQIAAAA2uVP_UOqpQ8kN5UusRJxtRTb-
vLQlFZmc2N8bgWI8YDPp5FEVBTeVqWarvzWD3SO7oLG9SYKPHZvRg"
type="text/javascript"></script>


New:


<script src="http://maps.google.com/maps?
file=api&amp;v=2.x&amp;key=ABQIAAAA2uVP_UOqpQ8kN5UusRJxtRTb-
vLQlFZmc2N8bgWI8YDPp5FEVBTeVqWarvzWD3SO7oLG9SYKPHZvRg"
type="text/javascript"></script>


Changelog:
- Added GDirections
- Added GDirectionsOptions
- Added GRoute
- Added GStep
- Added GTrafficOverlay
- Added GPlaceMark
- Added GGeocodeStatus
- Added GDirectionsDuration
- Added GDirectionsDistance (w/ additional sugar to convert from
meters)
- Changed GGeocoderAdvancedListener - new receieve GGeoStatusCode
object as opposed to an int onFail
- Changed GGeocodeResult -> getAddresses method has been removed in
favor of getPlacemarks which returns
- GPlaceMark objects (this is to maintain consistency between the
Geocoder and the Directions code basis... so I didn't have 2 parsers)
- Removed GGeocodeAddress


--------------------
Additional Notes:


Be sure to check your Hosted Mode log window to see if the GWT Maps
API is complaining about missing scripts or namespaces... it will
tell
you what to correct so that you are releasing maps applications that
are compatible across IE and FF.


--------------------
Road map:
1.) Add GPolylineEncoder class
2.) Fix any new bug requests
------------------------


Available for download on SourceForge
(http://sourceforge.net/projects/gwt/). For anyone interested in
helping help please e-mail me (developers, testers, documenters
welcome).


To use the API :


1.) Downlod the most current googleMaps.jar from
http://sourceforge.net/project/showfiles.php?group_id=169331


2.) Add googlemaps_gwt_2_2_1.jar to your project's classpath


2.1) Make sure you modify you project's command files
(Project-shell.cmd and Project-compile.cmd) to reference the
classpath


3.) Add the following line into your project's module:


<inherits name='com.mapitz.gwt.googleMaps.GoogleMaps' />


4.) To the HTML file's HEAD you intend to display a map on add the
google maps java script file along with your key (hopefully this is a
requirement that will go away)


Example:
<script
src="http://maps.google.com/maps?file=api&v=2.x&key=ABQIAAAA..."
type="text/javascript"></script>


5.) Work with the API in your code
To get started with the API:


//Instatiate the GMap2Widget
// The following instatiation will default the map to 37.4419,
-122.1419 and zoom level 13 size 300px by 300px
GMap2Widget mapWidget = new GMap2Widget("300", "300");


//Alternative method: Setting your own center value and zoom in
the
constructor
//GMap2Widget mapWidget = new GMap2Widget("300", "300",
new GLatLng(37.4419, -122.1419), 13);


//Retrieve the GMap2 object and start manipulating your map
final GMap2 gmaps = mapWidget.getGmap();


//Add the widget to your GWT UI (You can do this before or after
you call getGmap() now).


gmaps.openInfoWindowHtml(pos, "The center of the world");


6.) Example of adding a map event listeners


GMap2EventManager eventManager = GMap2EventManager.getInstance();


eventManager.addOnMoveStartListener(gmaps,
new GMap2EventMoveListener()
{
public void onMoveStart(GMap2 map)
{


searchStatusText.setText("Move
Started");
}


public void onMoveEnd(GMap2 map)
{
}


public void onMove(GMap2 map)
{
}
}
);


eventManager.addOnClickListener(gmaps, new
GMap2EventClickListener()
{
public void onClick(GMap2 map,
GOverlay


overlay, GLatLng point)
{


searchStatusText.setText("Clicked on " + point.toString());
}
}
);


7.) Example of adding a map marker event listeners
GMarkerEventManager markerEventManager =
GMarkerEventManager.getInstance();


markerEventManager.addOnInfoWindowOpenListener(gmarker, new
GMarkerEventInfoWindowListener()
{
public void onInfoWindowOpen(GMarker
marker)
{


searchStatusText.setText("Info
window open");
}


public void onInfoWindowClose(GMarker
marker)
{
}
}
);


markerEventManager.addOnDragEndListener(gmarker, new
GMarkerEventDragListener()
{
public void onDragEnd(GMarker marker)
{
searchStatusText.setText("On
drag end");
}


public void onDragStart(GMarker
marker)


{
}
}
);


8.) Using the geocoder


GFactualGeocodeCache cache = new GFactualGeocodeCache();
GClientGeocoder gcg = new GClientGeocoder(cache);


GGeocodeAdvancedResultListener advancedResultListener = new
GGeocodeAdvancedResultListener() {


public void onSuccess(GGeocodeResult result)
{
GLog.write(result.getName());

GLog.write(result.getStatus().getCode().getDesc());
GPlaceMark[] placemark =
result.getPlacemarks();
GLog.write("Size of array: " +
placemark.length);
GLog.write(placemark[0].getCounty());
}


public void onFail(GGeoStatusCode statusCode, String
address)
{
GLog.write(address);
GLog.write(statusCode.getDesc());
}
};


gcg.getLocations("A dog in the mud", advancedResultListener);
gcg.getLocations("4807 Fern Hollow, Austin, TX 78731",
advancedResultListener);

Sanjiv Jivan

unread,
Jun 3, 2007, 4:00:09 PM6/3/07
to Google Web Toolkit
I just started looking into using this lib. One question - Is there a
reason you're overriding onAttach() instead of onLoad() in
GMap2Widget?

Thanks for building this useful library.

Sanjiv

> 1.) Downlod the most current googleMaps.jar fromhttp://sourceforge.net/project/showfiles.php?group_id=169331

aglaforge

unread,
Jun 3, 2007, 5:49:44 PM6/3/07
to Google Web Toolkit
Sanjiv,

To be honest it's been a while since I did that part of the
implementation, but I recall that there was a specific reason that I
did pick onAttach over onLoad, at the time. What that reason was
*shrug*... looking at the Widget code I almost wonder if I was trying
to prevent the DOM.setEventListener() from invoking (or there might
have been some previous logic in the method I didn't care for). That
said, it might be worth taking a shot at switching to the onLoad
method to see if it causes any problems.

Cheers,

Anthony

> > advancedResultListener);- Hide quoted text -
>
> - Show quoted text -

Sanjiv Jivan

unread,
Jun 3, 2007, 6:17:24 PM6/3/07
to Google Web Toolkit
One more question : how complete is the gwt-maps API compared to the
real google maps Javascript API? Can you breifly mention the gaps that
you're aware of?

Thanks,
Sanjiv

aglaforge

unread,
Jun 3, 2007, 9:06:49 PM6/3/07
to Google Web Toolkit
Sanjiv,

It's a complete implementation of the Maps API, up through release
2.81 (which is the most current). With this current release there
should be no implementation gaps. All the objects in the maps API are
available in the GWT maps API with a near 1:1 mapping of method names
(~97%). That said there are some minor differences in the way things
are implemented, mostly around event management and geocoding
(additional interfaces), but really that just comes down to having
canned interfaces callback so it's more Java-esque and the developers
don't have to implement any special callbacks at the JS level
(basically to make the API simpler to use).

Cheers,

Aglaforge

lembas

unread,
Jun 26, 2007, 2:49:19 AM6/26/07
to Google Web Toolkit
Hi,

It is great to have an google maps api for gwt. thanks!

I have two questions and one suggestion.

First question is: Is there a support group or an email address for
this api?

Second: I do not understand why but gcg.getLocations("4807 Fern


Hollow, Austin, TX 78731",

advancedResultListener); always fails for me. Even for the cases "new
york city" or "california".

09:25:41:361New York City
09:25:41:376The given key is either invalid or does not match the
domain for which it was given.
09:25:41:454A dog in the mud
09:25:41:454The given key is either invalid or does not match the
domain for which it was given.
09:25:41:5014807 Fern Hollow, Austin, TX 78731
09:25:41:501The given key is either invalid or does not match the
domain for which it was given.
09:25:41:641California
09:25:41:641The given key is either invalid or does not match the
domain for which it was given.

what could be the problem?

My suggestion: the event handling seems a little bit different than
usual. For example the code below uses addOnInfoWindowOpenListener but
we cannot reach onInfoWindowClose method in
GMarkerEventInfoWindowListener class. Same would be the case for
addOnInfoWindowCloseListener and onInfoWindowOpen method in it.
Instead we could use a schema like addInfoWindowListener which again
takes GMarkerEventInfoWindowListener as second parameter which
contains both onInfoWindowOpen and onInfoWindowClose. Same for
mouseEvents: we can use just one addMouseListener instead of three
seperate addOnMouseMoveListener, addOnMouseOutListener and
addOnMouseOverListener methods.

krispy

unread,
Jun 26, 2007, 9:48:07 AM6/26/07
to Google Web Toolkit
Well, the problem is your API key - you need to have it registered to
whatever domain you're going to use inside the <script> tag for the JS
file. If you're not sure what's wrong, post your HTML file and let us
look at it.

I know what you mean about the listeners - it's a little bit annoying
to have to add yourself as a listener for _every_ event, but I think
Anthony did this so that you wouldn't have to receive unnecessary
event calls. You can change this behavior yourself, since Anthony's
code is open source (and is a very simple wrapper which is easy to
modify). Or maybe he'll change it for you - you can add an issue to
his sourceforge project:

http://sourceforge.net/projects/gwt/

-krispy

lembas

unread,
Jun 26, 2007, 10:32:49 AM6/26/07
to Google Web Toolkit
thanks Krispy. I got the key now. no problem now.

One can easily modify and extend the code.
Thanks again Anthony.

GWT-Beginner

unread,
Jul 2, 2007, 11:07:34 PM7/2/07
to Google Web Toolkit
While building the code using the compile script I get the following
error. I have followed all the steps above or so I think. Any ideas?

[ERROR] Errors in 'jar:file:/../googlemaps_gwt_2_2_1.jar!/com/mapitz/
gwt/googleMaps/client/JSObject.java'
[ERROR] Line 5: Implicit super constructor JavaScriptObject()
is undefined for default constructor. Must define an explicit
constructor
Finding entry point classes
[ERROR] Build failed


On Jun 26, 7:32 am, lembas <keremo...@gmail.com> wrote:
> thanks Krispy. I got the key now. no problem now.
>
> One can easily modify and extend the code.
> Thanks again Anthony.
>
> On Jun 26, 4:48 pm, krispy <cplum...@integrity-apps.com> wrote:
>
> > Well, the problem is your API key - you need to have it registered to
> > whatever domain you're going to use inside the <script> tag for the JS
> > file. If you're not sure what's wrong, post your HTML file and let us
> > look at it.
>
> > I know what you mean about the listeners - it's a little bit annoying
> > to have to add yourself as a listener for _every_ event, but I think
> > Anthony did this so that you wouldn't have to receive unnecessary
> > event calls. You can change this behavior yourself, since Anthony's
> > code is open source (and is a very simple wrapper which is easy to
> > modify). Or maybe he'll change it for you - you can add an issue to
> > his sourceforge project:
>
> >http://sourceforge.net/projects/gwt/
>
> > -krispy
>
> > On Jun 26, 2:49 am, lembas <keremo...@gmail.com> wrote:
>
> > > Hi,
>

> > > It is great to have angooglemapsapi for gwt. thanks!

Cabeza

unread,
Jul 28, 2007, 9:16:06 AM7/28/07
to Google Web Toolkit
Hi aglaforge and others,

I am sending you my html file from my GWT project (down below). I am
using GWT 1.4.10 on Windows, Java jdk1.5.0_11 and
googlemaps_gwt_2_2_1.jar. I did exactly what you advise to make google
maps work, but I am still getting the following ERROR in hosted mode
log window:

[ERROR] Google Maps GWT Configuration Error:
java.lang.Exception: The Javascript for the Google Maps API appears to
be missing from your HTML file
at
com.mapitz.gwt.googleMaps.client.GMap2Widget.sanityCheck(GMap2Widget.java:
144)
at
com.mapitz.gwt.googleMaps.client.GMap2Widget.<init>(GMap2Widget.java:
69)
at
com.mapitz.gwt.googleMaps.client.GMap2Widget.<init>(GMap2Widget.java:
64)
at eu.kyselica.brainpool.client.Brainpool.onModuleLoad(Brainpool.java:
18)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:342)
at
com.google.gwt.dev.shell.BrowserWidget.attachModuleSpace(BrowserWidget.java:
326)
at com.google.gwt.dev.shell.ie.BrowserWidgetIE6.access
$200(BrowserWidgetIE6.java:36)
at
com.google.gwt.dev.shell.ie.BrowserWidgetIE6$External.gwtOnLoad(BrowserWidgetIE6.java:
70)
at
com.google.gwt.dev.shell.ie.BrowserWidgetIE6$External.invoke(BrowserWidgetIE6.java:
125)
at
com.google.gwt.dev.shell.ie.IDispatchImpl.Invoke(IDispatchImpl.java:
293)
[INFO] PROBLEM DETECTED: The Javascript for the Google Maps API
appears to be missing from your HTML file.
[INFO] Recommendation: You should have a line like: <script


src="http://maps.google.com/maps?
file=api&amp;v=2&amp;key=ABQIAAAA2uVP_UOqpQ8kN5UusRJxtRTb-
vLQlFZmc2N8bgWI8YDPp5FEVBTeVqWarvzWD3SO7oLG9SYKPHZvRg" type="text/

javascript"></script> in your <HEAD></HEAD>

This is my html file:
====== NOT PART OF HTML
=============================================================
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-
microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html;
charset=utf-8"/>
<title>Brainpool</title>
<script language='javascript'
src='eu.kyselica.gmap.GMap.nocache.js'></script>

<style type="text/css">
v\:* {
behavior:url(#default#VML);
}
</style>
<script src="http://maps.google.com/maps?
file=api&amp;v=2.x&amp;key=ABQIAAAAYsCZ_9eJxrWxgEcVa_thSBQinM9fNMW5sHZ8Ay2yKVTYHlWYIRSmMATZyXN2jd6P5IISvp2R6yuJ8Q"
type="text/javascript">
</script>

</head>
<body>
<!-- OPTIONAL: include this if you want history support -->
<iframe src="javascript:''" id="__gwt_historyFrame" style="width:
0;height:0;border:0"></iframe>
</body>
</html>
====== NOT PART OF HTML
=============================================================

Please help me,

Thank you,
Michal

krispy

unread,
Jul 30, 2007, 9:42:42 AM7/30/07
to Google Web Toolkit
GWT-Beginner:

I'm sorry I didn't see this earlier, but your problem is because the
2.2.1 JAR is meant for the GWT 1.4RC - in 1.4, GWT changed the
JavaScriptObject constructor, so it broke the Maps API wrapper. You
can either go into Anthony's code and change it yourself to make it
work with GWT 1.3.3, or else you have to revert back to the 2.1.4
JAR. HTH!

-krispy

krispy

unread,
Jul 30, 2007, 9:50:01 AM7/30/07
to Google Web Toolkit
Michal,

I've seen this in someone else's code too - you can't have the GWT
script before the Maps API script. I believe it starts loading the
GWT Maps wrapper code, which looks for the maps script, which hasn't
arrived yet. What you should do is move the GWT <script> tag to the
<body> of your HTML document - according to the docs it's slightly
faster that way:

http://code.google.com/webtoolkit/documentation/com.google.gwt.doc.DeveloperGuide.Fundamentals.HostPage.html

At the least, I think you have to move the GWT <script> somewhere
after the Maps API script.

-krispy

GWT-Beginner

unread,
Jul 30, 2007, 11:24:55 PM7/30/07
to Google Web Toolkit
Thanks for all the help. This is a great library. I have another on a
related but different note. I am trying to use the geocoding API

String address = "600 Amphitheatre Parkway, Mountain View, CA, USA";

GClientGeocoder geocoder = new GClientGeocoder();
geocoder.getLatLng(address, new GGeocodeResultListener() {

public void onFail(String address) {
// TODO Auto-generated method stub
System.out.println("Failed to decode address: " + address);

}

public void onSuccess(GLatLng latlng) {
// TODO Auto-generated method stub
pos = latlng;
map.setCenter(pos, 13);
}

});


I get a failure.

Failed to decode address: 600 Amphitheatre Parkway, Mountain View, CA,
USA

I have the key in my html file. Other Map API works fine. The only
quirk is that I am using this in a test environment where I am using
this in a hosted mode(with url localhost:8888) and the.key is
registered to a different domain. I tried to register the key with
this domain but still does not work. This is also behind a firewall so
remote servers cant reach this host.

Any ideas?

On Jul 30, 6:50 am, krispy <cplum...@integrity-apps.com> wrote:
> Michal,
>
> I've seen this in someone else's code too - you can't have the GWT
> script before the Maps API script. I believe it starts loading the
> GWT Maps wrapper code, which looks for the maps script, which hasn't
> arrived yet. What you should do is move the GWT <script> tag to the
> <body> of your HTML document - according to the docs it's slightly
> faster that way:
>

> http://code.google.com/webtoolkit/documentation/com.google.gwt.doc.De...

Michal Kyselica

unread,
Jul 31, 2007, 7:30:26 AM7/31/07
to Google-We...@googlegroups.com
Thank you very much krispy,

you were right, all that was necessary, was to move my GWT script
behind the MapsAPI script.

Cheers,
Michal

krispy

unread,
Jul 31, 2007, 9:32:13 AM7/31/07
to Google Web Toolkit
Pamela from the Maps API forums offered a crazy insight that might be
what's giving you problems:

http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/f87f3e292d0dce71/20f5f308b2162c96#20f5f308b2162c96

I know that localhost and local file system URLs won't trigger a check
on the API key, but apparently what she's saying is that Geocoding
will always cause a key check (including directions). I'm sure this
is because they have a strict limit on how many Geocoding requests you
can make in a day (50,000 or so, AFAIK), which you can sometimes
surpass quickly if you get into infinite loops for a little while.
So, if you know you're not over the limit, try deploying this to an
actual URL (not localhost or a local file URL) and see if Geocoding
works then too. You might want to try the -noserver option for hosted
mode so that hosted mode points to the same URL for testing - HTH!

-krispy

Maciej Matecki

unread,
Aug 2, 2007, 7:42:14 AM8/2/07
to Google Web Toolkit

On 31 Lip, 05:24, GWT-Beginner <rishi.bharg...@gmail.com> wrote:
> Thanks for all the help. This is a great library. I have another on a
> related but different note. I am trying to use the geocodingAPI
>
> String address = "600 Amphitheatre Parkway, Mountain View, CA, USA";
>
> GClientGeocoder geocoder = new GClientGeocoder();
> geocoder.getLatLng(address, new GGeocodeResultListener() {
>
> public void onFail(String address) {
> // TODO Auto-generated method stub
> System.out.println("Failed to decode address: " + address);
>
> }
>
> public void onSuccess(GLatLng latlng) {
> // TODO Auto-generated method stub
> pos = latlng;
> map.setCenter(pos, 13);
> }
>
> });
>
> I get a failure.
>
> Failed to decode address: 600 Amphitheatre Parkway, Mountain View, CA,
> USA
>

> I have the key in my html file. Other MapAPIworks fine. The only


> quirk is that I am using this in a test environment where I am using
> this in a hosted mode(with url localhost:8888) and the.key is
> registered to a different domain. I tried to register the key with
> this domain but still does not work. This is also behind a firewall so
> remote servers cant reach this host.
>
> Any ideas?
>

Generate key for http://localhost:8888
It works for me.
Best regards,
Maciej Matecki

Madhu

unread,
Aug 10, 2007, 2:22:27 AM8/10/07
to Google Web Toolkit
Folks

First of all thanks for the gwt maps api. It rocks.

I have a question and was trying to figure out a solution where a user
can start typing a city for example and the autocomplete can fill in
the rest of the info. Does the api have any such functionality. I have
looked thru and cannot find anything.

Any ideas?

Thanks
Madhu

> Generate key forhttp://localhost:8888

krispy

unread,
Aug 13, 2007, 8:23:17 AM8/13/07
to Google Web Toolkit
Madhu, I don't think the geocoder supports this kind of functionality
right now - anyways, that would be more of a question for the Maps API
people. Right now, you'd have to make your own database of place
names and query it on each key up event that you get. Even if you
could get results that basically answer the question "is this what you
were trying to find?", they'd be incomplete at best and extremely non-
customizable - with a database you'd be able to create many more
interesting queries. That being said, I'm sure someone has a service
out there somewhere for looking up this kind of stuff - maybe you
could just create a web service client to talk to it. HTH!

-krispy

Reply all
Reply to author
Forward
0 new messages