[Serializable]
public class AddressForQueryIPFromBaidu
{
public string Address { get; set; }
public Content Content { get; set; }
public string Status { get; set; }
}
[Serializable]
public class Content
{
public string Address { get; set; }
public Address_Detail Address_Detail { get; set; }
public Point Point { get; set; }
}
[Serializable]
public class Address_Detail
{
public string City { get; set; }
public string City_Code { get; set; }
public string District { get; set; }
public string Province { get; set; }
public string Street { get; set; }
public string Street_Number { get; set; }
}
[Serializable]
public class Point
{
public string X { get; set; }
public string Y { get; set; }
}
public class AddressForQueryIPFromBaidu
{
public string Address { get; set; }
public Content Content { get; set; }
public string Status { get; set; }
}
[Serializable]
public class Content
{
public string Address { get; set; }
public Address_Detail Address_Detail { get; set; }
public Point Point { get; set; }
}
[Serializable]
public class Address_Detail
{
public string City { get; set; }
public string City_Code { get; set; }
public string District { get; set; }
public string Province { get; set; }
public string Street { get; set; }
public string Street_Number { get; set; }
}
[Serializable]
public class Point
{
public string X { get; set; }
public string Y { get; set; }
}
public class WebLocation
{
public static AddressForQueryIPFromBaidu GetAddressFromIP(string ipAddress)
{
var ip = Net.GetIP();
string baiduKey = "CkpxXeOIsBMtgI48ui1BLo7gvmtR5GIa";
string urllocation = "http://api.map.baidu.com/location/ip?ak=" + baiduKey + "&ip=" + ip + "&coor=bd09ll";
{
public static AddressForQueryIPFromBaidu GetAddressFromIP(string ipAddress)
{
var ip = Net.GetIP();
string baiduKey = "CkpxXeOIsBMtgI48ui1BLo7gvmtR5GIa";
string urllocation = "http://api.map.baidu.com/location/ip?ak=" + baiduKey + "&ip=" + ip + "&coor=bd09ll";
//string urllocation = "http://api.map.baidu.com/geocoder/v2/?location=36.68278473,117.02496707&output=xml&pois=1&ak=" + baiduKey;
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(urllocation);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
System.IO.Stream responseStream = response.GetResponseStream();
System.IO.StreamReader sr = new System.IO.StreamReader(responseStream, System.Text.Encoding.GetEncoding("utf-8"));
string responseText = sr.ReadToEnd();
sr.Close();
sr.Dispose();
responseStream.Close();
string jsonData = responseText;
JavaScriptSerializer jss = new JavaScriptSerializer();
AddressForQueryIPFromBaidu addressForQueryIPFromBaidu = jss.Deserialize<AddressForQueryIPFromBaidu>(jsonData);
return addressForQueryIPFromBaidu;
}
}
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(urllocation);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
System.IO.Stream responseStream = response.GetResponseStream();
System.IO.StreamReader sr = new System.IO.StreamReader(responseStream, System.Text.Encoding.GetEncoding("utf-8"));
string responseText = sr.ReadToEnd();
sr.Close();
sr.Dispose();
responseStream.Close();
string jsonData = responseText;
JavaScriptSerializer jss = new JavaScriptSerializer();
AddressForQueryIPFromBaidu addressForQueryIPFromBaidu = jss.Deserialize<AddressForQueryIPFromBaidu>(jsonData);
return addressForQueryIPFromBaidu;
}
}