0

我在 aspx 页面上使用 web 用户控件来显示谷歌地图上的位置,我将位置作为 ASPX 页面加载事件的参数传递到其中,并且每当加载页面时,我都会完美地获取位置。

每当用户在 ASPX 页面上单击“搜索”按钮搜索特定位置时,我都必须更改位置,并且我在“搜索”按钮单击事件中将位置传递给 Web 用户控件,但无法将位置获取到网络用户控制。

public partial class MapControl : System.Web.UI.UserControl
{
    public List<string> MyLocation {get; set; }
    protected void Page_Load(object sender, EventArgs e)
    {
        GeoCode geocode;
        List<GMarker> markers = new List<GMarker>();
        for (int i = 0; i < MyLocation.Count(); i++)
        {
            geocode = GMap1.getGeoCodeRequest(MyLocation[i]);
            GLatLng gLatLng = new GLatLng(geocode.Placemark.coordinates.lat, geocode.Placemark.coordinates.lng);
            GMap1.setCenter(gLatLng, 20, GMapType.GTypes.Normal);
            GMarker oMarker = new GMarker(gLatLng);
            markers.Add(oMarker);
            //GMap1.Add(oMarker);
            GListener listener = new GListener(oMarker.ID, GListener.Event.click, string.Format(@"function () {{ var w = new google.maps.InfoWindow(); w.setContent('<center>{0}</center>'); w.open({1}, {2});}}", "<b>" + MyLocation[i] + "</b>", GMap1.GMap_Id, oMarker.ID));
            GMap1.Add(listener);
        }

        GMap1.Add(new GMapUI());
        GMap1.GZoom = 10;

 protected void Button1_Click1(object sender, EventArgs e)
    {
 List<string> locations = new List<string>();
                for (int i = 0; i < ListView1.Items.Count; i++)
                {
                    Label addressline1 = (Label)this.ListView1.Items[i].FindControl("addr1");
                    string addrloc = addressline1.Text;
                    locations.Add(addrloc);
                }
                MapControl mc = LoadControl("~/MapControl.ascx") as MapControl;
                mc.MyLocation = locations;
}

我将此 Web 用户控件包含到 Search.aspx 文件中,并且当我从页面加载事件传递位置时,它的工作但当我尝试从搜索按钮单击事件传递位置时,将 Null 值转换为 Web 用户控件的 Mylocations 值为 null ..所以有没有办法用更新的位置重新加载用户控件。

4

1 回答 1

0

我想你可以在这里使用更新面板。您必须将谷歌地图保留在更新面板中,并将针对此按钮的触发器设置为您的地图。那我想你会得到你想要的。如果有任何困惑请告诉我

于 2013-07-25T05:56:16.407 回答