google map

    protected void Button1_Click(object sender, EventArgs e)
    {

        string sHtml = "";
        HttpWebRequest request;
        HttpWebResponse response = null;
        Stream stream;

        request = (HttpWebRequest)WebRequest.Create("http://maps.google.com/maps/geo?q=Brghghghkst+raat+336&output=xml&key=ABQIAAAAuaqmm8dDnhww8URMYtFCwhQpDmmpk8q921mRIPG4qgOvy0T09hSxaQUI-wgAo7USMOwfIrceghhDnA");
        response = (HttpWebResponse)request.GetResponse();
        stream = response.GetResponseStream();
        sHtml = new StreamReader(stream, System.Text.Encoding.Default).ReadToEnd();
        stream.Close();
        response.Close();

        int startPosition = sHtml.IndexOf("<coordinates>");
        int endPosition = sHtml.IndexOf("</coordinates>");
        if (startPosition >= 0 && endPosition >= 0)
        {
            string coordi = sHtml.Substring(startPosition, endPosition - startPosition);
            //Label2.Text = coordi;
            int douposition = coordi.LastIndexOf(",");
            coordi = coordi.Substring(0, douposition);
            Label1.Text = coordi;
        }
        else
        {
            Label1.Text = "no";
        }
    }

posted @ 2008-04-19 22:31  风轻如梦  阅读(212)  评论(0编辑  收藏  举报