GE in java application

710 views
Skip to first unread message

ding

unread,
May 26, 2010, 6:44:18 PM5/26/10
to KML Developer Support - Google Earth Plug-in
I know this question has been asked before but I was unimpressed with
the answer before, and since time has passed, I am hoping there might
be better examples now.

Can anyone explain (or point to another source that explains) how to
embed google earth into a java (desktop) application?

Cheers,

Ding

StarTraX

unread,
May 26, 2010, 11:00:08 PM5/26/10
to KML Developer Support - Google Earth Plug-in
I'm no Java programmer, but have successfully embedded the API into a
Windows .NET desktop application.
The key to success is to work in an environment that can execute
Javascript code. In my environment that was through .Net's webBrowser
class.
Don't know if something like that's available in the Java environment.

GTrek

unread,
May 27, 2010, 7:09:59 PM5/27/10
to KML Developer Support - Google Earth Plug-in
Hi Ding,

Are you trying to embed it in a web page or a windows app ?.

I extracted the following code from :-
http://earth-api-samples.googlecode.com/svn/trunk/demos/mapsapi/ggeoxml.html
This is usefull site and it's quite simple to understand.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=utf-8" />
<title>Using Google Earth with the Maps API - GGeoXml</title>

<!-- *** Replace the key below with your own API key, available at
http://code.google.com/apis/maps/signup.html *** -->
<script type="text/javascript" src="http://www.google.com/jsapi?
key=ABQIAA................"></script>

<script type="text/javascript">
google.load('maps', '2.160');
var map;
var geoXml;

function initialize() {
map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(37.4328, -122.077), 12);
map.addMapType(G_SATELLITE_3D_MAP);
var mapui = map.getDefaultUI();
mapui.maptypes.physical = false;
map.setUI(mapui);
map.setMapType(G_SATELLITE_MAP);
}

</script>

</head>
<body onload="initialize()" onunload="GUnload">

<div id="map" class="map" style="width:800px;height:600px"></div>
</body>
</html>

I think it should work although I haven't tested it.

John
www.gtrek.co.uk

ding

unread,
May 27, 2010, 11:52:16 PM5/27/10
to KML Developer Support - Google Earth Plug-in
trying to put it into a java app, rather than in a web page.

I have a full featured java application which deals with GPS devices
and saves data to a database and exports to KML.

Would love to add a google earth module to the software though so a
user can see their data without launching a seperate copy of GE.

-Ding

On May 28, 11:09 am, GTrek wrote:
> Hi Ding,
>
> Are you trying to embed it in a web page or a windows app ?.
>
> I extracted the following code from :-http://earth-api-samples.googlecode.com/svn/trunk/demos/mapsapi/ggeox...
> This is usefull site and it's quite simple to understand.
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
>                       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
> transitional.dtd">
> <html>
>   <head>
>     <meta http-equiv="content-type" content="text/html;
> charset=utf-8" />
>     <title>Using Google Earth with the Maps API - GGeoXml</title>
>
>     <!-- *** Replace the key below with your own API key, available athttp://code.google.com/apis/maps/signup.html*** -->

GTrek

unread,
May 28, 2010, 6:56:47 PM5/28/10
to KML Developer Support - Google Earth Plug-in
This is possible, the way I do it is from the application (I'm using
VB) call a function in the java with the KML as a parameter

Dim webObj(0) As Object
webObj(0) = KML.ToString
wbGEapi.Document.InvokeScript("finishLoadKml", webObj)

Then in the java

function finishLoadKml(kml) {
var kmlObject = ge.parseKml(kml)

// check if the KML was fetched properly
if (kmlObject) {
ge.getFeatures().appendChild(kmlObject);

obj_linestring_placemark = kmlObject;
obj_linestring_placemark.setVisibility('True');

} else {
alert('Bad KML, load failed');
}
}

John
www.gtrek.co.uk
Reply all
Reply to author
Forward
0 new messages