New Utility Library: Google Earth API

1,273 views
Skip to first unread message

Josh L

unread,
Mar 23, 2011, 9:08:15 PM3/23/11
to Google Maps JavaScript API v3
Hi all,

I wanted to let you know that there is a new library available at
http://code.google.com/p/google-maps-utility-library-v3/ that helps
you easily integrate the Earth API with your mashup.

You can download directly from http://google-maps-utility-library-v3.googlecode.com/svn/trunk/googleearth/

Please feel free to leave comments or feedback about it in this
thread.

Cheers,

-Josh

Nianwei Liu

unread,
Mar 25, 2011, 3:38:10 PM3/25/11
to Google Maps JavaScript API v3
Josh,
Thanks for the lib, much appreciated.
However, there are a few issues that I noticed:
.-- The code wipes off any custom map types, or settings in the
mapOptions.
-- There are shim code to allow maptype control to display on top of
the plugin, but somehow it did not show up on my firefox after I
switch to earth type and then back.

On Mar 23, 9:08 pm, Josh L <jli...@google.com> wrote:
> Hi all,
>
> I wanted to let you know that there is a new library available athttp://code.google.com/p/google-maps-utility-library-v3/that helps
> you easily integrate the Earth API with your mashup.
>
> You can download directly fromhttp://google-maps-utility-library-v3.googlecode.com/svn/trunk/google...

Nianwei Liu

unread,
Mar 25, 2011, 4:35:49 PM3/25/11
to Google Maps JavaScript API v3
One more observation:

This lib used a unique (and clever) technique to track overlays been
added to the map instance. It overwrites the Class.prototype.setMap
method by creating an alias pointer to the original function and call
it afterward using the alias. There is a potential risk introduced by
the closure compiler. There are other forum posters pointed this out
the closure forum before, so I just repeat here using this example:

The compiler renamed "setMapOriginal_" in the compile process, in the
actual result, it became google[B][a][E].q=google[B][a][E].setMap;
Now, there is no guarantee that it will always be renamed to "q"
because the compiler make decision based on the code. Hypothetically,
it can be renamed to something like "l".
Here is the problem: if the core API class has already have something
called "q" or "l", it will break. Since the core API is compiled
independently from this lib, future release can break it. I was able
create a sample just demo that.

I renamed the "q" method to "l" in the compiled code (again, it
entirely possible for the compiler to produce it but I did it for demo
purpose). Now check this link:

http://gmaps-utility-gis.googlecode.com/svn/trunk/v3test/earthv3/earth_compiled.html?v=3.2

This link loads API 3.2. Now click through the top link to load
different version of core API, you will see 3.3 works fine, but, the
KML layer (Chicago transit) broke in 3.4. It's because there is an new
"l" function in the KMLLayerOverlay class introduced in 3.4 that
clashed with the earth lib code.

So, I think setMapOriginal_ method probably should be protected using
quote so the compiler would leave it along, assuming the core API will
never have something called setMapOriginal_.





On Mar 25, 3:38 pm, Nianwei Liu <nian...@gmail.com> wrote:
> Josh,

en4ce

unread,
Mar 25, 2011, 4:39:28 PM3/25/11
to Google Maps JavaScript API v3
i saw that as well and i´am really exited, finally its here, its not a
super performer and the cool transition from the other maptypes to
earth from V2 is not there, but still, finally something!

i tryed to implement it, i think it can work but i wonder how to set
the map type like "map.setMapTypeId(google.maps.MapTypeId.EARTH)" via
a custom Map Type button and a click event, any suggestion?

Josh L

unread,
Mar 26, 2011, 11:52:11 AM3/26/11
to Google Maps JavaScript API v3
Hi there,

Good question: The MapTypeId is not registered in
google.maps.mapTypeId, but you can set it directly by using:
map.setMapTypeId('GoogleEarthAPI'); -- I will add this to the
documentation as well.

Cheers,

-Josh

en4ce

unread,
Mar 26, 2011, 2:02:15 PM3/26/11
to Google Maps JavaScript API v3
sorry that dont work, it throws an "c is undefined" error in the
googleearth-compiled.js, i did include the file from the google server
it self

there is no error msg in chrome but in ff within firebug

see it here: http://www.youspots.com/search_startpage2.php

Cheers,
-Enrico

Josh Livni

unread,
Mar 26, 2011, 2:06:10 PM3/26/11
to google-map...@googlegroups.com

Ah thanks for pointing that out.  There are a couple other things I will also make available in an update next week.

> --
> You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
> To post to this group, send email to google-map...@googlegroups.com.
> To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.
>
Message has been deleted
Message has been deleted

en4ce

unread,
Mar 26, 2011, 3:00:40 PM3/26/11
to Google Maps JavaScript API v3
i cant wait to have my map finally in 3D, please keep us updated, if
you need more testing just tell us

i noticed another error with the map controls

- if mapTypeControl: false, it throws the "c is undefined" error
- if mapTypeControl: true, everything works as expected but the custom
controls that are added to the map before, are gone... you should
check for that value and add the custom map controls as well

cheers

On 26 Mrz., 19:06, Josh Livni <jli...@google.com> wrote:
> Ah thanks for pointing that out.  There are a couple other things I will
> also make available in an update next week.

Josh L

unread,
Mar 26, 2011, 11:49:23 AM3/26/11
to Google Maps JavaScript API v3
Hi Nianwei,

Thanks for the detailed feedback, greatly appreciated. I was unable
to replicate the issue you were having in Firefox, can you tell me the
version and operating system you are using?

Also you make a great point that the setMapOriginal_ method should
have been protected; I will get a fix out for this shortly.

Cheers,

-Josh

On Mar 25, 1:35 pm, Nianwei Liu <nian...@gmail.com> wrote:
> One more observation:
>
> This lib used a unique (and clever) technique to track overlays been
> added to the map instance. It overwrites the Class.prototype.setMap
> method by creating an alias pointer to the original function and call
> it afterward using the alias. There is a potential risk introduced by
> the closure compiler. There are other forum posters pointed this out
> the closure forum before, so I just repeat here using this example:
>
> The compiler renamed "setMapOriginal_" in the compile process, in the
> actual result, it became google[B][a][E].q=google[B][a][E].setMap;
> Now, there is no guarantee that it will always be renamed to "q"
> because the compiler make decision based on the code. Hypothetically,
> it can be renamed to something like "l".
> Here is the problem: if the core API class has already have something
> called "q" or "l", it will break. Since the core API is compiled
> independently from this lib, future release can break it.  I was able
> create a sample just demo that.
>
> I renamed the "q" method to "l" in the compiled code (again, it
> entirely possible for the compiler to produce it but I did it for demo
> purpose). Now check this link:
>
> http://gmaps-utility-gis.googlecode.com/svn/trunk/v3test/earthv3/eart...

Josh L

unread,
Mar 30, 2011, 8:16:07 PM3/30/11
to Google Maps JavaScript API v3
Hi all,

I've just pushed a minor update to this library that
- protects setMapOriginal_
- provides a MAP_TYPE_ID constant you can use, a la:
map.setMapTypeId(GoogleEarth.MAP_TYPE_ID);
- updates the reference html

I'm not around the rest of this week but next week I'll look at some
of the other issues/requests, such as maps that have disabled the
mapTypeControl or have non-default map types. My intention is to
continually improve this library over the coming months, so your
feedback is always appreciated.

Cheers,

-Josh

en4ce

unread,
Mar 31, 2011, 6:20:14 AM3/31/11
to Google Maps JavaScript API v3
good work and thoughts, keep it comming

i tested the map.setMapTypeId(GoogleEarth.MAP_TYPE_ID); and it works
like the old version "map.setMapTypeId('GoogleEarthAPI');"
but shouldn't it be something like
"map.setMapTypeId(google.maps.MapTypeId.EARTH);" or am i missing
something there ?

thanks josh

-- enrico

Luke Mahé

unread,
Mar 31, 2011, 6:06:58 PM3/31/11
to google-map...@googlegroups.com, en4ce
We prefer the utility libraries don't use the same namespace as the API to avoid confusion between open source libraries and the core API.

-- Luke


ajuarez

unread,
Apr 1, 2011, 4:47:35 PM4/1/11
to Google Maps JavaScript API v3
Hi, I'm trying insert the option Earth in my page, this is in google
maps v3,
then I'm put this code in my page:
[code]
var Qro = new google.maps.LatLng(20.60,-100.40);
var myOptions = {
zoom: 13,
center: Qro,
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetViewControl: true
}
map= new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var ge = new GoogleEarth(map);
[/code]
and send me the Error: uncaught exception: google.earth not loaded
I guess I need the next line:
google.load('earth', '1');
but my html don't run.
could you help me??
thanks.

Josh L

unread,
Apr 5, 2011, 8:19:39 PM4/5/11
to Google Maps JavaScript API v3
Hi there,

Yes you are correct and you need to explicitly call
google.load('earth','1') in your code. Now that I think about it,
however, I should put the google.load function within the utility
library, and I will do that with the next release.

In the meantime, be sure you first loaded the javascript (for example
with a script source of "http://www.google.com/jsapi?key=YOUR_KEY">)
and then call the google.load('earth','1') in your code before
attempting to instantiate a new GoogleEarth object.

Cheers,

-Josh

Barry Hunter

unread,
Sep 11, 2012, 10:35:21 AM9/11/12
to google-map...@googlegroups.com
can get the underlying Google Earth instance, with getInstance()

so just need to add something like

var ge = googleEarth.getInstance();

to the top of that function. Where googleEarth is the global variable
containing the GoogleEarth object.


On Mon, Sep 10, 2012 at 9:14 PM, Sean Frank <ja...@go3dexpansion.com> wrote:
> I have gotten this example working and worked plenty with the Google Earth
> plugin and V2 of Maps. I was curious as to how to access the flyto and
> lookat functions onclick.
>
> Previously you could call a function like this within an anchor link and it
> will flyto when clicked
>
> function viewSouth() {
> var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
> // Set the position values
> lookAt.setLatitude(28.54626988796781);
> lookAt.setLongitude(-81.37704984953177);
> lookAt.setRange(1070.448301908147); //default is 0.0
> lookAt.setTilt(67.84202025905072);
> lookAt.setHeading(-179.9640072336487);
> ge.getView().setAbstractView(lookAt);
> }
>
>
>
> This it seems doesnt work with the new integration method. Could I possibly
> get some quick instruction as to how to access this function withing the
> Maps V3/Google Earth Integration
>
>
> Thanks in advance!
>
>
>
>
>
>
>
>
> On Wednesday, March 23, 2011 9:08:15 PM UTC-4, Josh Livni (Google Employee)
> On Wednesday, March 23, 2011 9:08:15 PM UTC-4, Josh Livni (Google Employee)
> --
> You received this message because you are subscribed to the Google Groups
> "Google Maps JavaScript API v3" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-maps-js-api-v3/-/nGK6RnvblI4J.
Reply all
Reply to author
Forward
0 new messages