The Maps v3 API you've been waiting for, now in pre-release

7,042 views
Skip to first unread message

Eric Ayers

unread,
Mar 30, 2012, 4:43:44 PM3/30/12
to gwt-google-apis, David Carlson
We've worked with the Maps team to create an updated GWT bindings API
for Maps v3. I've uploaded a pre-release now that you can check out
at:

http://code.google.com/p/gwt-google-apis/downloads/detail?name=gwt-maps-3.8.0-pre1.zip

Thanks to the work of David Carlson, this API is automatically
generated from metadata coming directly from the Maps API source. The
great news is that since the API is now automatically generated, we
expect that we will be able to periodically release updates that will
keep them in sync with the published JS apis. On the other hand,
since these are mechanically translated from the JS API, some of the
conventions might be a little odd to Java programmers.

For the casually curious, you can peruse the javadoc:

http://gwt-google-apis.googlecode.com/svn/javadoc/maps/3.8/index.html

Currently, the sample code and the directions for trying them out are
a little rough, we hope to make that nicer before the actual release.

Please followup to this thread if you have any questions.

-Eric.
--
Eric Ayers | Software Engineer | zun...@google.com | +1 404 487 9229

Brandon Donnelson

unread,
Mar 30, 2012, 7:39:42 PM3/30/12
to gwt-goo...@googlegroups.com, David Carlson
Wahoo! :) Nice work.

Brandon Donnelson

Joseph R Lust

unread,
Mar 30, 2012, 8:49:49 PM3/30/12
to gwt-goo...@googlegroups.com
Brandon,

On cursory examination:

  • Javadoc comments are quite incomplete in their auto generated classes, just the text block clipped from the JS API. No @link, @see, @param, @return etc for better Eclipse auto-suggestion and JavaDocs.
  • All constructors use create(), now uses of createJso() or newInstance()
  • All numeric inputs are double, whereas yours uses ints (assuming this is b/c only true numeric type in JS is double)
  • They stick to the letter to the JS API, so while you use a Java Enum as the ScaleControlStyle enum, they don't, thus for that type they have 7 method calls defined, while you just do 3 since the Enum type handles the rest (i.e. they must do ScaleControlStyle.getDefault(), you do ScaleControlStyle.DEFAULT) (i.e. since they are not an Enum, they use an internal registry of Map<Double,ScaleControlStyle> to store values. Seems wasteful).
  • Classes like MVCObject are not generics like yours, and only JS types are used (string, boolean, jso). This would make it harder to access using Java.
  • Because of use of doubles, array indexes like in MVCArray are looked up by double, not int, which seems odd if you're accessing from Java.
  • Requests don't use work around to prevent gwt_object dev mode errors in Chrome (which folks will notice I bet).
  • Different names, they make a new GoogleMap.create(), you make a MapImpl.newInstance() - only object in src prefixed with Google... funny, this is GWT, right?
    • They create map with a Node, you use Element. Official API says Node.
    • Seems they found the gwt_Object error here, it's removed if not running as isScript()

Obviously the two are not the same. My take away is that their implementation tries to stay as close to the JS as possible, even making their implementation notably more complex in places, rather than using the Java equivalent types. This probably is a wash or slight gain once compiled to JS, but does not seem to be as good a fit for GWT Java programming, and defies the reasoning of using the GWT compiler to transition from Java to JS. As a Java programmer, I would rather use Java idioms for Enums, rather than a clunky JS inspired Java wrapper for an Enum.

The plus is that theirs is generated from the GMaps source, so it would be easier to maintain in theory, but a diff of the API docs from one Maps release to the next would also allow straight forward upgrading of your API too, which is replete with tests I don't see in theirs, though they might have them somewhere as the full source is not out.


Sincerely,
Joseph


--
You are subscribed to the Google Groups "GWT-Google-Apis" group.
For more options, visit http://groups.google.com/group/gwt-google-apis?hl=en

Message has been deleted
Message has been deleted

Brandon Donnelson

unread,
Mar 30, 2012, 9:18:15 PM3/30/12
to gwt-goo...@googlegroups.com
Thanks for the awesome summary Joseph. 

Piers

unread,
Apr 1, 2012, 4:51:50 AM4/1/12
to Google API Libraries for GWT
I just tried swapping out gwt-maps3-0.2b and I'm getting the following
exceptions depending on when I create the map.


com.google.gwt.core.client.JavaScriptException: (TypeError): Cannot
read property 'maps' of undefined
at
com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:
248)
at
com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:
136)
at
com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:
561)
at
com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:
269)
at
com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:
91)
at com.google.maps.gwt.client.LatLng$.create(LatLng.java)
at com.milkrun.client.ui.AppAdminView.buildMap(AppAdminView.java:
36)
at com.milkrun.client.ui.AppAdminView.<init>(AppAdminView.java:32)
at
com.milkrun.client.ClientFactoryImpl.<clinit>(ClientFactoryImpl.java:
51)


I simply took the MapSimple.java code and included it into my app:

public void buildMap(){
LatLng myLatLng = LatLng.create(-34.397, 150.644);
MapOptions myOptions = MapOptions.create();
myOptions.setZoom(8.0);
myOptions.setCenter(myLatLng);
myOptions.setMapTypeId(MapTypeId.ROADMAP);
GoogleMap.create(mapContainerPanel.getElement(), myOptions); //
mapContainerPanel is a SimplePanel
}

my javascript is pretty weak but I gather it's similar to a java null
pointer exception for 'maps'. Any insight into what this is and why
it's returning null?

Eric Ayers

unread,
Apr 1, 2012, 10:35:50 AM4/1/12
to gwt-goo...@googlegroups.com
Looks like you don't have the Maps API loaded. You'll need to load it
with the AjaxLoader API or a <script> tag . See the README file.

> --
> You are subscribed to the Google Groups "GWT-Google-Apis" group.
> For more options, visit http://groups.google.com/group/gwt-google-apis?hl=en

--

Message has been deleted
Message has been deleted

Piers

unread,
Apr 2, 2012, 3:47:08 AM4/2/12
to Google API Libraries for GWT
> > For more options, visithttp://groups.google.com/group/gwt-google-apis?hl=en
>
> --
> Eric Ayers | Software Engineer | zun...@google.com | +1 404 487 9229begin_of_the_skype_highlighting            +1 404 487 9229      I feel a little foolish. Sorry I did load the API but I copied the wrong stack trace.

From what the little bit more reading I've done I think it's due to
the rendering sequence with the declarative layout. Would it be
possible to include an example using UiBinder for those of us who use
it?

Caused by: com.google.gwt.core.client.JavaScriptException:
(TypeError): Cannot read property 'offsetWidth' of null
at
com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:
248)
at
com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:
136)
at
com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:
561)
at
com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:
269)
at
com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:
91)
at com.google.maps.gwt.client.GoogleMap$.create(GoogleMap.java)
at com.milkrun.client.ui.AppAdminView.renderMap(AppAdminView.java:
50)
at
com.milkrun.client.activity.AppNavActivity.start(AppNavActivity.java:
37)
at
com.google.gwt.activity.shared.ActivityManager.tryStart(ActivityManager.java:
214)
at
com.google.gwt.activity.shared.ActivityManager.onPlaceChange(ActivityManager.java:
141)
at
com.google.gwt.place.shared.PlaceChangeEvent.dispatch(PlaceChangeEvent.java:
70)
at
com.google.gwt.place.shared.PlaceChangeEvent.dispatch(PlaceChangeEvent.java:
1)
at com.google.gwt.event.shared.GwtEvent.dispatch(GwtEvent.java:1)
at
com.google.web.bindery.event.shared.EventBus.dispatchEvent(EventBus.java:
40)
at
com.google.web.bindery.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:
193)
at
com.google.web.bindery.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:
88)
at
com.google.gwt.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:
52)
at
com.google.gwt.place.shared.PlaceController.goTo(PlaceController.java:
156)
at
com.milkrun.client.ui.AppHeaderView.onListBasketButtonClick(AppHeaderView.java:
50)

Thanks for the quick response.

JoyaleXandre

unread,
Apr 2, 2012, 5:49:36 PM4/2/12
to gwt-goo...@googlegroups.com, David Carlson
Is it normal that when I reload the same composite twice, the second time the map layout is all mixed up? If I do a complete refresh all is OK.

cyclingthealps

unread,
Apr 15, 2012, 9:38:20 AM4/15/12
to gwt-goo...@googlegroups.com, David Carlson
Cool Eric!!!

I am already using the bindings of Brandon Donnelson!
He did a fantastic job on this as well!!

Interesting to see the summary of Joseph as well.

Thanks for the work. 
Working with the Maps API in GWT is just great!

Cheers

Eric Ayers

unread,
Apr 15, 2012, 6:43:11 PM4/15/12
to gwt-goo...@googlegroups.com

This is mostly the work of David Carlson with integration help from the Maps Api team out of Sydney.  I'm glad Brandon's work is out there too.

--

Brandon Donnelson

unread,
Apr 15, 2012, 9:21:02 PM4/15/12
to gwt-goo...@googlegroups.com
Thank you :)

Have a good day,
Brandon Donnelson

Joseph R Lust

unread,
Apr 16, 2012, 6:52:46 PM4/16/12
to gwt-goo...@googlegroups.com
Eric,

Congrats on your and David's work. My apologies if my commentary was at all acerbic.


Sincerely,
Joseph

dubiousandrew

unread,
Apr 17, 2012, 12:58:32 PM4/17/12
to Google API Libraries for GWT
I have been playing around with the new API. I have been trying to
figure out how I can bind a polyline and a marker. So that when the
marker is moved or the line is edited both update their positions. I
would like to do something like this:

public class Line extends MVCObject {
MVCArray<LatLng> array;
public Line(MVCArray<LatLng> array){
this.array = array;
}
public LatLng get(String key){//ERROR Cannot override final method
from MVCObject
return this.array.getAt(Double.parseDouble(key));
}
public void set(String key, LatLng latlng){
this.array.setAt(Double.parseDouble(key), latlng);
}
public MVCArray<LatLng> getPath(){
return array;
}

}

//create a polyline
PolylineOptions polyOpts = PolylineOptions.create();
polyOpts.setStrokeColor("red");
polyOpts.setStrokeOpacity(0.5);
polyOpts.setStrokeWeight(3);
polyOpts.setEditable(true);
Polyline poly = Polyline.create(polyOpts);

//bind the polyline to a line
MVCArray<LatLng> array = MVCArray.create();
Line line = new Line(array);
line.getPath().push(latlng);
poly.setPath(line.getPath());
poly.setMap(map);

//create a marker
MarkerOptions markerOptions = MarkerOptions.create();
markerOptions.setMap(map);
markerOptions.setTitle("Hello World!");
markerOptions.setDraggable(true);
Marker start = Marker.create(markerOptions);

//bind the marker to the begining of the line
start.bindTo("position", line, "0");


But I am not allowed to do it because I cannot override the final get
method of the MVCObject.
Is there something else I can do to bind a marker and a polyline? I
can't seem to figure it out. Any help would be greatly appreciated.
-Andrew

On Mar 30, 2:43 pm, Eric Ayers <zun...@google.com> wrote:
> We've worked with the Maps team to create an updated GWT bindings API
> for Maps v3.  I've uploaded a pre-release now that you can check out
> at:
>
>  http://code.google.com/p/gwt-google-apis/downloads/detail?name=gwt-ma...
Reply all
Reply to author
Forward
0 new messages