2012-11-18 82 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,它工作正常。

相关问题