0

Google のジオコーディング サービスを使用してデータをジオコーディングする必要があります。Google のジオコーディング サービスは、Bing のように .NET 経由での使用には適していません (驚くことではありません)。そのため ContractDataSerializers、WCF、JSON、およびその他の頭字語の山をすべて使用できますが、以下のようなものには何か問題があります。私が必要とするのは、たとえば、緯度と経度です。

string url = String.Format("http://maps.google.com/maps/api/geocode/xml?address=blah&region=ie&sensor=false", HttpUtility.UrlEncode(address));

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(url);
XmlNodeList xmlNodeList = xmlDocument.SelectNodes("/GeocodeResponse/result");

if (xmlNodeList != null)
{
   // Do something here with the information
}

多くの先行開発作業以外に、他のアプローチでは正確に何が得られるのでしょうか? 私はWCF、DataContracts、ServiceContractsなどに非常に慣れていますが、ここで何をもたらすかわかりません...

4

2 に答える 2

1

XDocument を WebRequest と共に使用します。次のが役立つ場合があります。

public static GeocoderLocation Locate(string query)
{
    WebRequest request = WebRequest.Create("http://maps.google.com/maps?output=kml&q="
        + HttpUtility.UrlEncode(query));

    using (WebResponse response = request.GetResponse())
    {
        using (Stream stream = response.GetResponseStream())
        {
            XDocument document = XDocument.Load(new StreamReader(stream));

            XNamespace ns = "http://earth.google.com/kml/2.0";

            XElement longitudeElement = document.Descendants(ns + "longitude").FirstOrDefault();
            XElement latitudeElement = document.Descendants(ns + "latitude").FirstOrDefault();

            if (longitudeElement != null && latitudeElement != null)
            {
                return new GeocoderLocation
                {
                    Longitude = Double.Parse(longitudeElement.Value, CultureInfo.InvariantCulture),
                    Latitude = Double.Parse(latitudeElement.Value, CultureInfo.InvariantCulture)
                };
            }
        }
    }

    return null;
}
于 2010-09-24T12:40:25.617 に答える
1

codeplex で GoogleMap コントロール プロジェクトを使用します: http://googlemap.codeplex.com/

Google でジオコーディングを行うためのクラスがあります: http://googlemap.codeplex.com/wikipage?title=Google%20Geocoder&referringTitle=Documentation

于 2010-09-24T11:34:40.277 に答える