I am working on a web application that builds a KML file using a list of coordinates and is supposed to display them on Google maps when you click a button. When I'm testing it on desktop it works, as it brings up google earth with no problem. However, when I try to test it on an android device, I get "This community map can not be displayed due to errors". Funny thing is, is that I navigated to google's KML samples page, and I was able to open them up without incident. I added this to my web.config file:
<staticContent>
<mimeMap fileExtension=".kml" mimeType="application/vnd.google-earth.kml+xml" />
<mimeMap fileExtension=".kmz" mimeType="application/vnd.google-earth.kmz" />
</staticContent>
This is the code that generates the KML file:
Public Sub BuildKML()
Dim latList As Generic.List(Of String) = Session("latList")
Dim longList As Generic.List(Of String) = Session("longList")
My.Response.Clear()
My.Response.ContentType = "application/vnd.google-earth.kml+xml"
My.Response.AddHeader("Content-Disposition", "attachment; filename=OrderMap.kml")
'uncomment following line to view raw xml
'My.Response.ContentType = "plain/text"
My.Response.ContentEncoding = System.Text.Encoding.UTF8
Dim stream As New System.IO.MemoryStream
Dim XMLwrite As New XmlTextWriter(stream, System.Text.Encoding.UTF8)
XMLwrite.Formatting = Formatting.Indented
XMLwrite.Indentation = 3
XMLwrite.WriteStartDocument()
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteStartElement("kml")
XMLwrite.WriteAttributeString("xmlns", "http://www.opengis.net/kml/2.2")
XMLwrite.WriteAttributeString("xmlns:gx", "http://www.google.com/kml/ext/2.2")
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteStartElement("Folder")
XMLwrite.WriteWhitespace(Environment.NewLine)
For i As Integer = 0 To latList.Count - 1
XMLwrite.WriteStartElement("Placemark")
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteElementString("name", "Point" & i.ToString)
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteElementString("description", "This is a point in the order")
XMLwrite.WriteWhitespace(Environment.NewLine)
Dim longitude As String = longList(i)
Dim latitude As String = latList(i)
XMLwrite.WriteStartElement("Point")
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteElementString("coordinates", longitude & "," & latitude & ",0")
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteEndElement()
XMLwrite.WriteWhitespace(Environment.NewLine)
XMLwrite.WriteEndElement()
Next
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())
My.Response.BinaryWrite(bytes)
My.Response.End()
End Sub
So, what exactly am I doing wrong here?