The sequence does not contain mvc3 elements GoogleMaps.LocationServices

I have an unusual problem. When I create an XML file with XmlElementin MVC3, I sometimes get this error (1 out of 5 times)

The sequence contains no elements.

[InvalidOperationException: The sequence contains no elements]
System.Linq.Enumerable.First (source IEnumerable`1) +336
GoogleMaps.LocationServices.GoogleLocationService.GetLatLongFromAddress (String address) +185

In my controller, I have this code:

using GoogleMaps.LocationServices;

public ActionResult Index()
        {
            XmlDocument doc = new XmlDocument();
            XmlDeclaration documentType = doc.CreateXmlDeclaration("1.0", "utf-8", null);
            doc.AppendChild(documentType);
            XmlElement markers = doc.CreateElement("markers");
            doc.AppendChild(markers);
            var locationService = new GoogleLocationService();
            foreach (var item in repository.Mreza.ToList())
            {
                XmlElement marker = doc.CreateElement("marker");

                XmlElement name = doc.CreateElement("name");
                XmlElement address = doc.CreateElement("address");
                XmlElement tel = doc.CreateElement("tel");
                XmlElement fax = doc.CreateElement("fax");
                XmlElement time2 = doc.CreateElement("time2");
                XmlElement more = doc.CreateElement("more");
                XmlElement lat = doc.CreateElement("lat");
                XmlElement lng = doc.CreateElement("lng");

                name.InnerText = item.Ime;
                address.InnerText = item.Ulica;
                tel.InnerText = item.Telefon;
                fax.InnerText = item.Fax;
                time2.InnerText = item.Email;
                more.InnerText = item.Web;

                var point = locationService.GetLatLongFromAddress(item.Grad);
                lat.InnerText = Convert.ToString(point.Latitude);
                lng.InnerText = Convert.ToString(point.Longitude);

                marker.AppendChild(name);
                marker.AppendChild(address);
                marker.AppendChild(tel);
                marker.AppendChild(fax);
                marker.AppendChild(time2);
                marker.AppendChild(more);
                marker.AppendChild(lat);
                marker.AppendChild(lng);

                markers.AppendChild(marker);
            }
            string URL = Server.MapPath("Content/NovoLayout/adreseXML.xml");
            doc.Save(URL);

            return View();
        }

Does anyone know what is wrong?

0
source share
1 answer

xml ? Google , , , . GoogleLocationService ( 100 ) , .

0

Source: https://habr.com/ru/post/1536780/


All Articles