0
我正在開發一個模塊,它可以獲取IP地址,並檢查城市,州,緯度,經度等所有代碼沒有問題,但如何我可以檢索數據並將其顯示在我的TextBlock上嗎?如何設置_geoLoc.City等的文本塊上的按鈕點擊
public class TestGeo
{
GeoLoc _geoLoc = new GeoLoc();
internal GeoLoc GetMyGeoLocation()
{
try
{
var request = WebRequest.Create(new Uri("http://geoiptool.com/data.php")) as HttpWebRequest;
if (request != null)
{
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727)";
using (var webResponse = request.GetResponse() as HttpWebResponse)
if (webResponse != null)
{
using (var reader = new StreamReader(webResponse.GetResponseStream()))
{
var doc = new XmlDocument();
doc.Load(reader);
var nodes = doc.GetElementsByTagName("marker");
// Guard.AssertCondition(nodes.Count > 0, "nodes", new object());
var marker = nodes[0] as XmlElement;
Guard.AssertNotNull(marker, "marker");
_geoLoc.City = marker.GetAttribute("city");
_geoLoc.Country = marker.GetAttribute("country");
_geoLoc.Code = marker.GetAttribute("code");
_geoLoc.Host = marker.GetAttribute("host");
_geoLoc.Ip = marker.GetAttribute("ip");
_geoLoc.Latitude = marker.GetAttribute("lat");
_geoLoc.Longitude = marker.GetAttribute("lng");
_geoLoc.State = GetMyState(_geoLoc.Latitude, _geoLoc.Longitude);
return _geoLoc;
}
}
}
return new GeoLoc();
}
catch (Exception ex)
{
throw;
}
}
謝謝,它真的幫了很多,真的很感激它。它解決了我的問題。 – user3016854
我很高興能幫上忙。如果此答案解決了您的問題,請按照本網站上的慣例[請標記爲正確](http://stackoverflow.com/help/someone-answers),以便其他用戶知道此問題有解決方案。謝謝。 – Sheridan