Google地图使用db值绑定页面加载

时间:2012-07-24 10:53:07

标签: google-maps

我正在尝试将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&amp;t=m&amp;ll=21.125498,81.914063&amp;spn=14.315343,18.676758&amp;z=5&amp;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&amp;t=m&amp;ll=" + lat + "," + lon + "&amp;spn=" + lat + "," + lon + "amp;z=5&amp;output=embed");
        DataBind();
    }
}

1 个答案:

答案 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");
    }
}