Google Maps Api会返回ZERO RESULT

时间:2014-05-03 14:13:18

标签: c# google-maps geocoding

我在我的项目中使用Google Maps API,但我遇到了问题。当我尝试将lat lon转换为城市时,我的物体很少,一切都很好。当我很多对象的一些对象被成功转换,但有些返回ZERO RESULT但是当我第二次尝试转换所有对象时,第一次尝试ZERO RESULT的某些对象在第二次尝试时成功转换。此外,当我复制返回ZERO RESULT的链接并将其放入浏览器时,Google会显示正确的XML结果。

任何人都可以帮助我吗?

代码:

    private void abc(string City)  // translating lat lon to City and shows it on map
    {
        if (NetworkInterface.GetIsNetworkAvailable() == true)
        {
            String Address = String.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=false", City);
            WebClient webClientCity = new WebClient();
            webClientCity.OpenReadCompleted += new OpenReadCompletedEventHandler(webClientCity_OpenReadCompleted);
            webClientCity.OpenReadAsync(new Uri(Address));
        }
    }

    private void webClientCity_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
        Pushpin pushpin1;
        Location a1 = new Location();
        XMLParserCity _Cparser;
        _Cparser = XMLParserCity.Instance;
        try
        {
            using (var reader = new StreamReader(e.Result))
            {
                string data = reader.ReadToEnd();
                if (data != null)
                {
                    _Cparser.DataToParse = data;
                    _Cparser.ParseStateData();
                }
                foreach (geometry st in _Cparser.CStateCollection)
                {
                    pushpin1 = new Pushpin() { Tag = "pushpin" };
                    a1.Latitude = st.lat;
                    a1.Longitude = st.lng;
                    pushpin1.Template = null;
                    pushpin1.Content = new Ellipse()
                    {
                        Fill = new SolidColorBrush(Colors.Red),
                        Stroke = new SolidColorBrush(Colors.Black),
                        StrokeThickness = 4,
                        Opacity = .8,
                        Height = 25,
                        Width = 25
                    };
                    MapLayer.SetPosition(pushpin1, a1);
                    map1.Children.Add(pushpin1);
                    a1.Latitude = st.lat;
                    a1.Longitude = st.lng;
                    location.Add(a1);
                }
            }
        }
        catch (Exception bl)
        {
            //MessageBox.Show(bl.Message);
        }
    }

2 个答案:

答案 0 :(得分:0)

" ZERO_RESULTS"表示地理编码成功但未返回任何结果。如果地理编码器传递了不存在的地址,则可能会发生这种情况。尝试使用一些静态地址并检查。

答案 1 :(得分:0)

我试过,结果是一样的。在第一次尝试时返回ZERO RESULT并在另一次尝试中返回成功结果。