Problems with generating kml from aspx page

36 views
Skip to first unread message

bb2j3z

unread,
Jun 6, 2008, 11:17:50 AM6/6/08
to KML Developer Support - KML Server Side Scripting
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()

ManoM

unread,
Jun 8, 2008, 11:22:35 PM6/8/08
to KML Developer Support - KML Server Side Scripting
Hi bb2j3z,

I don't know vb.net, but one way to approach it is to use a
NetworkLink and point to the script.

Mano

jpwade_bsu

unread,
Jul 25, 2008, 2:13:08 AM7/25/08
to KML Developer Support - KML Server Side Scripting
check file type association for the operating system of the computers
that dont work correctly.

jpwade
www.czmartin.com/jpw

barryhunter [KML Guru]

unread,
Jul 26, 2008, 10:37:51 AM7/26/08
to KML Developer Support - KML Server Side Scripting
I just gave similar advice in another thread (re php) but the same
should work for VB

Response.ContentDisposition = "attachment;
filename=""example.kml"""

added just after the ContentType line should help!

(I think vbscript excapes " as "" if not use \" or however else you
print out a " :)
Reply all
Reply to author
Forward
0 new messages