調用百度api輸出地址和城市查詢出具體座標系

在工做中遇到標題的內容,不知道如何寫,後來個人領導寫了一套代碼,感受非常厲害,特在此收藏,留做記念html

public static string GetResponse(string address, string region) { address = System.Web.HttpUtility.UrlEncode(address); region = System.Web.HttpUtility.UrlEncode(region); string url = string.Format("http://api.map.baidu.com/place/v2/search?query={0}&region={1}&scope={2}&output=xml&ak=這裏填寫你申請的ak", address, region, "2"); System.Net.HttpWebRequest request; request = (System.Net.HttpWebRequest)WebRequest.Create(url); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); //打印返回值 
        Stream stream = response.GetResponseStream();   //獲取響應的字符串流 
        StreamReader sr = new StreamReader(stream); //建立一個stream讀取流 
        string responseString = sr.ReadToEnd();   //從頭讀到尾,放到字符串html 
        return responseString; }
相關文章
相關標籤/搜索