1

緯度/経度に基づいて場所の詳細を取得するために、Windows Phone 7 アプリでhttp://www.geoplugin.com/webservices/extrasという Web サービスを使用しようとしていました。私は最初にランダムな値で Web サービスを試し、この xml ファイルを取得しました

<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。

コードまたはサービスに何か問題がありますか?? または、同じ結果を得るために使用できる他のサービスがある場合は教えてください。

4

1 に答える 1

0

geoplugin api を破棄し、Bing maps api を使用したところ、問題なく動作しました。

于 2013-04-06T23:54:11.303 に答える