我正在尝试将iFrame中的Google地图(在页面加载时)与数据库值绑定:
<iframe id="myMap" runat="server" width="291" height="241" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src=""></iframe><br /><small><a href="https://maps.google.co.in/?ie=UTF8&t=m&ll=21.125498,81.914063&spn=14.315343,18.676758&z=5&source=embed" style="color:#0000FF;text-align:left">View Larger Map</a><br />
我使用的是以下代码,但我在iFrame中获得的只是一个空白框:
public void GetMapDetails(int Propertyid){
DataSet dstPropMap = Tbl_PropertyMaster.GetPropertyDetailsbyId(Propertyid);
if (dstPropMap.Tables[0].Rows.Count > 0)
{
lat = dstPropMap.Tables[0].Rows[0]["Latitude"].ToString();
lon = dstPropMap.Tables[0].Rows[0]["Longitude"].ToString();
myMap.Attributes.Add("src", "https://maps.google.co.in/?ie=UTF8&t=m&ll=" + lat + "," + lon + "&spn=" + lat + "," + lon + "amp;z=5&output=embed");
DataBind();
}
}
答案 0 :(得分:0)
好的我解决了这个, 出于某种原因使用Attributes.Add将属性添加到IFrame无法正常工作,所以我切换到html IMG 图片,并将runat =“server”标记添加到其中。
<强>即强>
<img id="myMap" runat="server" width="291" height="241"/>
并在代码后面添加了Attributes.Add到IMG
public void GetMapDetails(int Propertyid)
{
DataSet dstPropMap = Tbl_PropertyMaster.GetPropertyDetailsbyId(Propertyid);
if (dstPropMap.Tables[0].Rows.Count > 0)
{
lat = dstPropMap.Tables[0].Rows[0]["Latitude"].ToString().Trim();
lon = dstPropMap.Tables[0].Rows[0]["Longitude"].ToString().Trim();
myMap.Attributes.Add("src", "http://maps.google.com/maps/api/staticmap?center=" + lat + "," + lon + "&zoom=11&size=291x241&sensor=true");
}
}