Javascript written using C# for google earth

Jan 29, 2013 at 11:19 AM

hi,

   I have to display KML data in Google earth. So I written entire html and Java script code using c# as mentioned bellow. Now i am not able to display kml data in Google earth but I want to display kml data in Google earth. for me Google earth is displaying without kml data. If i add kml data to javascript throwing error.

Please let me know resolve solution.

Kml file Data:

<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Camera>
<longitude>-122.444633</longitude>
<latitude>37.801899</latitude>
<altitude>139.629438</altitude>
<heading>-70.0</heading>
<tilt>75</tilt>
</Camera>
<Placemark><name>Placemark from KML string</name>
<Point><coordinates>-122.448425,37.802907,0</coordinates></Point>
</Placemark>
</Document>
</kml>

C# code for html and Java script:

 

string

kmlData =GetKmlData();

 

 

string javascriptCode = "<html>"

+

 

"<head>"

+

 

"<title>Sample</title>"

+

 

"<script type=" + "\"" + "text/javascript" + "\""

+

"src=" + "\"" + "http://www.google.com/jsapi?key=ABQIAAAAwbkbZLyhsmTCWXbTcjbgbRSzHs7K5SvaUdm8ua-Xxy_-2dYwMxQMhnagaawTo7L1FE1-amhuQxIlXw" + "\"" + ">"

+

"</script>"

+

"<script type=" + "\"" + "text/javascript" + "\"" + ">"

+

"var ge =null;"

+

"google.load(" + "'earth'," + "'1'" + ");"

+

 

"function init() {"

+

 

"google.earth.createInstance('map3d', initCB, failureCB);" + "}"

+

 

"function initCB(instance) { "

+

 

"ge = instance;"

+

 

"ge.getWindow().setVisibility(true);"

+

 

"var kmlString = '" + kmlData + "';"

+

 

"var kmlObject = ge.parseKml(kmlString);"

+

 

"ge.getFeatures().appendChild(kmlObject);"

+

 

"ge.getView().setAbstractView(kmlObject.getAbstractView());"

+

 

"}"

+

 

"function failureCB(errorCode) {" + "}"

+

 

"function getScript(){alert('This is JavaScript Method Called from C# code');}"

+

 

"google.setOnLoadCallback(init);"

+

 

"</script>"

+

 

"</head>"

+

 

"<body>"

+

 

"

+ "\"" + "map3d" + "\"" + ">
"

+

 

"</body>"

+

 

"</html>"

;

geBrowser.NavigateToString(javascriptCode);

 

public string

GetKmlData()

{

 

StreamReader sr = new StreamReader(@"D:\Users\cchellu\Desktop\Latest1.KML"

);

 

var

kmlString = sr.ReadToEnd();

 

 

return

kmlString.Trim();

}

Jan 31, 2013 at 8:03 AM
hello ;}
Developer
Jan 31, 2013 at 5:03 PM
This discussion area is about the CodePlex website itself. For questions related to a project on CodePlex, such as Enterprise Library, AJAX Control Toolkit, SharePoint Learning Kit, or Web Client Software Factory, you should find the project in the project directory and enter your question in the discussion area for the project.