I have an aspx page that is generating kml in vb.net... it works fine
on my computer as in when I click on the link to the aspx page..
google earth starts up and it shows the plot point.
However on a couple other machines. It is not doing the same
behavior. I thought it was the mime types so I set up the following
in IIS.
application/vnd.google-earth.kml+xml .kml
application/vnd.google-earth.kmz .kmz
On one machine with Vista, when I click on the link... dreamweaver
since it sees the .aspx extension wants to load the kml in
dreamweaver. I thought I had the proper mime types set up in the
response type. If I save the source as a kml file, it works fine
when I link from the server. Anyone have any insight?
Here's the sample code:
' Construct KML File
Response.ContentType = "application/vnd.google-
earth.kml+xml"
Response.ContentEncoding = System.Text.Encoding.UTF8
Dim stream As New System.IO.MemoryStream
Dim XMLwrite As New XmlTextWriter(stream, System.Text.Encoding.UTF8)
Dim icon As String = "
http://www.walls.com/map/images/icons/red-
dot.png"
XMLwrite.WriteStartDocument()
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteStartElement("kml")
XMLwrite.WriteAttributeString("xmlns", "
http://earth.google.com/kml/
2.0")
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteStartElement("Placemark")
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteElementString("Snippet", strAddress)
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteElementString("description", strAddress)
XMLwrite.WriteElementString("name", strName)
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteStartElement("LookAt")
XMLwrite.WriteElementString("longitude", dGeoLongitude)
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteElementString("latitude", dGeoLatitude)
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteElementString("range", "300")
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteElementString("tilt", "20")
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteElementString("heading", "0")
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteEndElement()
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteElementString("visibility", "1")
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteStartElement("Style")
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteStartElement("IconStyle")
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteStartElement("Icon")
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteElementString("href", icon)
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteElementString("w", "-1")
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteElementString("h", "-1")
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteEndElement()
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteEndElement()
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteEndElement()
XMLwrite.WriteStartElement("Point")
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteElementString("extrude", "1")
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteElementString("altitudeMode", "relativeToGround")
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteElementString("coordinates", dGeoLongitude & ", " &
dGeoLatitude & ", 0")
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteEndElement()
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteEndElement()
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteEndElement()
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteEndDocument()
XMLwrite.Flush()
Dim reader As IO.StreamReader
stream.Position = 0
reader = New IO.StreamReader(stream)
Dim bytes() As Byte =
System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd())
Response.BinaryWrite(bytes)
Response.End()