protected void getip() { string ips = HttpContext.Current.Request.UserHostAddress; // 获取ip string url = "http://api.map.baidu.com/location/ip?ak=f23sfw323#swer&ip=" + ips + "&coor=bd09ll&callback=?"; // System.Net.WebClient web = new System.Net.WebClient(); // 在后台调用 url string result = web.DownloadString(url); // 获取调用url 的返回值 if (result.Split(',').Length >= 11 && !string.IsNullOrWhiteSpace(result.Split('}')[1].Split(':')[2].Split(',')[0].Replace(""", "")) && !string.IsNullOrWhiteSpace(result.Split('}')[1].Split(':')[3].Replace(""", ""))) { CurX= result.Split('}')[1].Split(':')[2].Split(',')[0].Replace(""", ""); // 获取百度地图坐标点,这个url就是根据ip返回坐标点 CurY = result.Split('}')[1].Split(':')[3].Replace(""", ""); } else { CurX = "114.52208184"; // 若无 标点,默认石家庄 CurY = "38.04895831"; } }