ashx处理程序和谷歌地图没有显示点

时间:2013-09-04 09:29:01

标签: google-maps kml ashx

我在使用谷歌地图和ashx处理程序在地图上生成点时遇到问题。 这真的很奇怪,因为我以前一直在使用它们,但没有问题。

处理程序正常,但点不会显示在地图上。

所以生成的文件是:

    <?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
   <Document>
      <Placemark>
         <name>Bla</name>
         <description>&lt;div class="ExternalClassEA84F87DED7745D594D3D4236376E796"&gt;dfdfg&lt;/div&gt;</description>
         <Point>
            <coordinates>19.8106635766601,41.3390789318785</coordinates>
         </Point>
      </Placemark>
   </Document>
</kml>

注意:如果我在google网站上传这个kml文件并使用该kml网址,则可以正常工作:/

我用来创建通用处理程序的代码是:

System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

        context.Response.ContentType = "application/vnd.google-earth.kml+xml";
        context.Response.AddHeader("Content-Disposition", "attachment; filename=Pikat.kml");
        context.Response.Expires = -1;


        XmlTextWriter kml = new XmlTextWriter(context.Response.OutputStream, System.Text.Encoding.UTF8);
        kml.Formatting = Formatting.Indented;
        kml.Indentation = 3;

        kml.WriteStartDocument();

        kml.WriteStartElement("kml", "http://www.opengis.net/kml/2.2");
        kml.WriteStartElement("Document");
        String place = String.Empty;
        place = context.Request.QueryString["place"];

        if (!String.IsNullOrEmpty(place))
        {
            #region Places Of Interests

            SPListItemCollection places = this.GetPlacesOfInterest(context);
            kml = GeneratePlacemarkElementForPlaceOfInterests(kml, places, context);

            #endregion
        }



        private XmlTextWriter GeneratePlacemarkElementForPlaceOfInterests(XmlTextWriter kml, SPListItemCollection places, HttpContext context)
    {
        int i = 0;
        if (places != null)
        {
            foreach (SPListItem item in places)
            {
                kml.WriteStartElement("Placemark");
                kml.WriteAttributeString("id", String.Format("{0}", i + 1));

                // kml.WriteElementString("id", String.Format("{0}", Cases.IndexOf(item) + 1));
                kml.WriteElementString("name", item["Title"].ToString());
                string HtmlDesc = String.Format(@"<Table width='300px'>
                        <tr><td><b>Titulli: </b></td><td>{0}</td></tr>
                        <tr><td><b>Kategoria: </b></td><td>{1}</td></tr>
                        <tr><td><b>Adresa:</b> </td><td>{2}</td></tr>
                        <tr><td><b>Pershkrimi:</b> </td><td>{3}</td></tr>
                        <tr><td><b>Orari:</b> </td><td>{4}</td></tr>
                        <tr><td><b>Me shume:</b> </td><td>{5}</td></tr>
                            </table><br/>",
                                              item["Title"] == null ? "--" : item["Title"].ToString(),
                    item["Category"] == null ? "--" : item["Category"].ToString(),
                    item["Address"] == null ? "--" : item["Address"].ToString(),
                    item["Description"] == null ? "--" : item["Description"].ToString(),
                    item["HoursOfOperation"] == null ? "--" : item["HoursOfOperation"].ToString(),
                    item["SiteUrl"] == null ? "--" : item["SiteUrl"].ToString());
                kml.WriteElementString("description", HtmlDesc);
                // show the Geometry

                kml.WriteStartElement("Point");
                string x = item["Longitude"].ToString(); string y = item["Latitude"].ToString();
                kml.WriteElementString("coordinates", String.Format("{0},{1}", x, y));
                kml.WriteEndElement(); // </Point>    
                kml.WriteEndElement(); // </Placemark> 

                i++;
            }
        }
        return kml;

1 个答案:

答案 0 :(得分:0)

好吧,这是一个愚蠢的防火墙问题。 其他一切都还不错