예제 #1
0
    //protected void btnPostback_Click(object sender, EventArgs e)
    //{
    //    //label.Text = "Hello After postback by clicking postback button";
    //}


    //protected void btnLabel_Click(object sender, EventArgs e)
    //{
    //    //label.Text = "Hello after clicking change label msg button";
    //}



    protected void btnSearch_Click(object sender, EventArgs e)
    {
        var results = GoogleMapAPIGetLatLong.GoogleMapAPIGeoCoding(txtSearch.Text.Trim());

        var resultCount = results.Elements("result").Count();

        lvDidYouMean.Visible = false;
        lblNoResults.Visible = false;

        // How many results did we get back?
        if (resultCount == 0)
        {
            //Eep, no results!
            lblNoResults.Visible = true;
        }

        else if (resultCount == 1)
        {
            //Got back just one result, show the stores that match the address search
            ShowResults(results);
        }

        else
        {
            //Got back multiple results - We need to ask the user which address they mean to use...
            var matches = from result in results.Elements("result")
                          let formatted_address = result.Element("formatted_address").Value
                                                  select formatted_address;

            lvDidYouMean.DataSource = matches;
            lvDidYouMean.DataBind();
            lvDidYouMean.Visible = true;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            var address = Request.QueryString["Address"];
            if (string.IsNullOrEmpty(address))
            {
                Response.Redirect("default.aspx");
            }


            // Get the lat/long info about the address
            var results = GoogleMapAPIGetLatLong.GoogleMapAPIGeoCoding(address);

            lblAddress.Text = address;

            // Set the latitude and longtitude parameters based on the address being searched on
            dsSearchResults.SelectParameters["Latitude"].DefaultValue  = results.Element("result").Element("geometry").Element("location").Element("lat").Value;
            dsSearchResults.SelectParameters["Longitude"].DefaultValue = results.Element("result").Element("geometry").Element("location").Element("lng").Value;

            lvSearchResults.DataBind();


            // Loop through each nearby location and build up the JavaScript to place the markers
            var markers = new List <string>();

            var nearbyLocations = dsSearchResults.Select(DataSourceSelectArguments.Empty) as DataView;
            foreach (DataRowView location in nearbyLocations)
            {
                markers.Add(string.Format(
                                @"{{ 

                                    title: ""Property #{0}"",
                                    position: new google.maps.LatLng({1}, {2}),
                                    url: ""PropertyDetails.aspx?PropertyID={3}""
                                }}",
                                location["PropertyID"],
                                location["Latitude"],
                                location["Longitude"],
                                location["PropertyID"]

                                )
                            );
            }

            var lat           = results.Element("result").Element("geometry").Element("location").Element("lat").Value;
            var lng           = results.Element("result").Element("geometry").Element("location").Element("lng").Value;
            var locationsJson = "[" + string.Join(",", markers.ToArray()) + "]";

            // Inject the Google Maps script
            ClientScript.RegisterStartupScript(this.GetType(), "Google Maps Initialization",
                                               string.Format("init_map('map_canvas', {0}, {1}, 15, {2});", lat, lng, locationsJson), true);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            var address = Request.QueryString["Address"];
            if (string.IsNullOrEmpty(address))
            {
                Response.Redirect("FindProperty.aspx");
            }


            // Get the lat/long info about the address
            var results = GoogleMapAPIGetLatLong.GoogleMapAPIGeoCoding(address);

            lblAddress.Text = address;

            // Set the latitude and longtitude parameters based on the address being searched on
            dsSearchResults.SelectParameters["Latitude"].DefaultValue  = results.Element("result").Element("geometry").Element("location").Element("lat").Value;
            dsSearchResults.SelectParameters["Longitude"].DefaultValue = results.Element("result").Element("geometry").Element("location").Element("lng").Value;

            lvSearchResults.DataBind();
        }
    }