GE - Open KML File on Google Earth
Viewing data from Google Earth - Google Maps
In the previous articles I explained about What is KML (Keyhole Markup Language)?, Google Fusion Table - An Introduction, How to open KML file on Google Maps API, Google Fusion Tables Layer | An Overview, What is GE? and How to use Google Earth?.
In this article I will explain how to display a KML file on Google Earth, Viewing Google Earth files, how to open a KML, Opening a KML File in Google Maps in web application.
Google Maps can read KML or KMZ, the file formats Google Earth uses for the exchange of geographic information. This means that you can view data you create and share with Google Earth on Google Maps. You can use this feature to plot multiple points of interest, draw lines, and mark regions on Maps.Find the source code below:
Google Maps can read KML or KMZ, the file formats Google Earth uses for the exchange of geographic information. This means that you can view data you create and share with Google Earth on Google Maps. You can use this feature to plot multiple points of interest, draw lines, and mark regions on Maps.Find the source code below:
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Displaying
a KML file on Google Earth</title>
<script src="http://www.google.com/jsapi?key=false" type="text/javascript"></script>
<script type="text/javascript">
var ge;
google.load("earth",
"1");
function
init() {
google.earth.createInstance('map3d', initCallback, failureCallback);
}
function
initCallback(instance) {
ge = instance;
ge.getWindow().setVisibility(true);
//
add a navigation control
ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
//
add some layers
ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS,
true);
// in
this sample we will attempt
// to
fetch a KML file and show it
function
finished(object) {
if
(!object) {
//
wrap alerts in API callbacks and event handlers
//
in a setTimeout to prevent deadlock in some browsers
setTimeout(function () {
alert('Bad or null KML.');
}, 0);
return;
}
ge.getFeatures().appendChild(object);
var
la = ge.createLookAt('');
la.set(19.068482, 72.833884,
15, ge.ALTITUDE_RELATIVE_TO_GROUND, 180, 60, 500);
ge.getView().setAbstractView(la);
}
//
fetch the KML
var
url = 'your_kml_name.kml';
google.earth.fetchKml(ge, url,
finished);
document.getElementById('installed-plugin-version').innerHTML =
ge.getPluginVersion().toString();
}
function
failureCallback(errorCode) {
}
</script>
</head>
<body onload="init()"
style="font-family: arial,
sans-serif; font-size: 13px; border: 0;">
<form id="form1" runat="server">
<h3>Displaying a
KML file on Google Earth</h3>
<div>
Installed Plugin Version: <span id="installed-plugin-version"
style="font-weight: bold;">
Loading...</span>
</div>
<br />
<div id="map3d" style="width: auto; height: 500px;">
</div>
</form>
</body>
</html>
Note: The KML file should be on public IP.
Please leave your comments, suggestions and queries about this post in the comment sections in order for me to improve my writing skills and to showcase more useful posts. Thanks for reading!
GE - Open KML File on Google Earth
Reviewed by Ravi Kumar
on
4:47 PM
Rating:
No comments: