Javascript 将Google地图添加到项目中并使用ASP.NET从数据库检索位置
我的意思是我用xml文件检索数据库,我希望它是xml文件,并且有一些字段我想在谷歌地图上显示,比如“城市,国家,街道,经度,latitude“我希望从此字段中获取值并将其显示在google地图上。我希望在页面加载事件中显示此地图。我不知道如何从xml文件检索数据并将其传递给地图 这是代码隐藏Javascript 将Google地图添加到项目中并使用ASP.NET从数据库检索位置,javascript,asp.net,xml,google-maps,google-maps-api-3,Javascript,Asp.net,Xml,Google Maps,Google Maps Api 3,我的意思是我用xml文件检索数据库,我希望它是xml文件,并且有一些字段我想在谷歌地图上显示,比如“城市,国家,街道,经度,latitude“我希望从此字段中获取值并将其显示在google地图上。我希望在页面加载事件中显示此地图。我不知道如何从xml文件检索数据并将其传递给地图 这是代码隐藏 void GetTableFromXMlData(string strResult) { CreateTable(); XmlDataDocument xmlDataDoc = new Xm
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);
}
}
一种从xml到地图的转换,一旦您拥有xml格式的数据,您的工作就完成了一半以上。您现在需要做的是稍微玩一下Javascript
- 您必须使用
初始化谷歌地图李>函数initialise()
- 在
中定义map选项
和map大小
类型
- 创建
class&Geocoder
class的实例infoWindow
- 最后编写函数加载标记,其中标记由坐标表示为纬度和经度的组合,信息窗口显示其余数据,如街道、国家代码、城市名称、Zipcode