【问题标题】:Adding Google Maps to project and retrive locatons from database using ASP.NET使用 ASP.NET 将 Google 地图添加到项目并从数据库中检索位置
【发布时间】:2015-04-08 12:29:59
【问题描述】:

我的意思是我有 xml 文件检索我想要它作为 xml 文件的数据库,并且有我想在谷歌地图上显示它的字段,例如“城市、国家、街道、经度、纬度”我想从这些字段中获取值和在谷歌地图上显示它。我想在页面加载事件中显示这个地图。问题我不知道如何从 xml 文件中检索数据并将其传递给地图。

这是后面的代码,

void GetTableFromXMlData(string strResult)
{
    CreateTable();
    XmlDataDocument xmlDataDoc = new XmlDataDocument();
    xmlDataDoc.LoadXml(strResult);
    foreach (XmlNode n in xmlDataDoc.DocumentElement.GetElementsByTagName("Property"))
    {
        DataRow dr = dtSearchResult.NewRow();
        dr["HotelID"] = n.Attributes["IDHotel"].Value;
        dr["HotelName"] = n.Attributes["Hotelname"].Value;

        dr["MinRate"] = n.Attributes["MinRate"].Value;
        dr["MaxRate"] = n.Attributes["MaxRate"].Value;
        dr["StarCategory"] = n.Attributes["StarCategory"].Value;
        dr["ImageIdentifier"] = n.Attributes["ImageIdentifier"].Value;
        dr["VPhotoPath"] = strVirtualPath + n.Attributes["ImageIdentifier"].Value + "_Exterior.jpg";
        if (n.HasChildNodes)
        {
            foreach (XmlNode childNode in n)
            {
                switch (childNode.Name)
                {
                    case "GEOData":///----->>>> here this the data i want to display it in a map.
                        {
                            dr["CountryCode"] = childNode.Attributes["CountryCode"].Value;
                            dr["CityName"] = childNode.Attributes["City"].Value;
                            dr["CityID"] = childNode.Attributes["IDCity"].Value;
                            dr["Zip"] = childNode.Attributes["Zip"].Value;
                            dr["Street"] = childNode.Attributes["Street"].Value;
                            dr["Longitude"] = childNode.Attributes["Longitude"].Value;
                            dr["Latitude"] = childNode.Attributes["Latitude"].Value;



                            break;
                        }
                    case "Distances":
                        {
                            foreach (XmlNode cChildNode in childNode)
                            {
                                if (cChildNode.Attributes["Type"].Value == "1")
                                    dr["DistanceToCity"] = cChildNode.Attributes["Distance"].Value;
                                else
                                    dr["DistanceToAirPort"] = cChildNode.Attributes["Distance"].Value;
                            }
                            break;
                        }
                    case "Descriptions":
                        {
                            dr["Descriptions"] = childNode.FirstChild.Attributes["Text"].Value;
                            ((Label)FindControl("lblHoDescription1")).Text = childNode.FirstChild.Attributes["Text"].Value;
                            break;
                        }
                    case "Meals":
                        {
                            dr["MinimumMeals"] = childNode.Attributes["MinimumMeals"].Value;
                            break;
                        }
                    default: break;
                }
            }
        }
        dtSearchResult.Rows.Add(dr);
    }
}

【问题讨论】:

    标签: javascript asp.net xml google-maps google-maps-api-3


    【解决方案1】:

    从 xml 到地图的 example

    【讨论】:

      【解决方案2】:

      一旦您拥有 XML 格式的数据,您就完成了一半以上的工作。您现在需要做的是稍微玩一下 Javascript。

      • 您必须使用function initialise() 初始化谷歌地图。
      • MapOption 中定义mapsizetype
      • 创建Geocoder 类和infoWindow 类的实例。
      • 最后编写函数来加载标记,其中标记由纬度和经度组合的坐标表示,信息窗口显示街道、国家代码、城市名称、邮政编码等其余数据。

      关于详细解释,您可以查看tutoriallarrp 发布的相同内容。

      【讨论】:

        猜你喜欢
        • 2019-03-16
        • 1970-01-01
        • 1970-01-01
        • 2019-06-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多