2012-11-18 81 views
1

我試圖在windows phone 7應用程序中使用web服務:http://www.geoplugin.com/webservices/extras以獲取基於緯度/經度的位置的詳細信息。 我第一次嘗試用隨機值的Web服務,得到了該XML文件在windows phone 7中使用geoplugin silverlight應用程序

<geoPlugin> 
    <geoplugin_place>Redmond</geoplugin_place> 
    <geoplugin_countryCode>US</geoplugin_countryCode> 
    <geoplugin_region>Washington</geoplugin_region> 
    <geoplugin_regionAbbreviated>WA</geoplugin_regionAbbreviated> 
    <geoplugin_latitude>47.6739900</geoplugin_latitude> 
    <geoplugin_longitude>-122.1215100</geoplugin_longitude> 
    <geoplugin_distanceMiles>0.07</geoplugin_distanceMiles> 
    <geoplugin_distanceKilometers>0.11</geoplugin_distanceKilometers> 
</geoPlugin> 

但是,當我在我的應用程序使用相同的試了一下,它返回一個空的XML文件。 下面的代碼:

private void Button_Click(object sender, RoutedEventArgs e) 
    { 
     GeoCoordinateWatcher pos = new GeoCoordinateWatcher(); 
     pos.Start(); 
     var mypos = pos.Position; 
     pos.Stop(); 
     double latitude = 47.674; 
     double longitude = -122.12; 
     if (!mypos.Location.IsUnknown) 
     { 
      latitude = mypos.Location.Latitude; 
      longitude = mypos.Location.Longitude; 
     } 
     WebRequest.RegisterPrefix("http://www.geoplugin.net/extras", WebRequestCreator.ClientHttp); 
     Uri req = new Uri(string.Format("http://www.geoplugin.net/extras/location.gp?lat={0}&long={1}&format=xml", latitude, longitude)); 
     WebClient downloader = new WebClient(); 
     downloader.OpenReadCompleted += new OpenReadCompletedEventHandler(downloader_OpenReadCompleted); 
     downloader.OpenReadAsync(req); 
    } 
void downloader_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) 
    { 
     if (e.Error == null) 
     { 
      XmlReader reader = XmlReader.Create(e.Result); 
      reader.ReadStartElement("geoplugin_place"); 
      textBox1.Text = reader.ReadContentAsString(); 

     } 
    } 

它給出了一個例外:元素「geoplugin_place」沒有被發現。第2行,第2位。

我的代碼或服務有什麼問題嗎? 或者如果有任何其他服務可以用來獲得相同的結果,請告訴我。

回答

0

我放棄了geoplugin api並使用了Bing地圖API,它工作正常。

相關問題