I have C# code written and suddenly it is throwing an error. But the strange thing is, it works sometimes but also throws an error sometimes:
The remote server returned an error: (403) Forbidden.
Please see the code if you see any issues:
C#
char[] delimiterChars = { ',' };
XmlDocument xmldoc = new XmlDocument();
string url = "https://maps.googleapis.com/maps/api/geocode/xml?address=Richmond&sensor=false";
xmldoc.Load(url); // I get the error on this line.
XmlNode LattNode =
xmldoc.SelectSingleNode("/GeocodeResponse/result/geometry/location/lat");
XmlNode LongNode = xmldoc.SelectSingleNode("/GeocodeResponse/result/geometry/location/lng");
// if condition here to check if LattNode and LongNode.InnerText is not empty
longitude = Convert.ToDouble(LongNode.InnerText);
lattitude = Convert.ToDouble(LattNode.InnerText);
return true;
Please see the error's screenshot here: https://snag.gy/u3QhaV.jpg
When you type this URL "https://maps.googleapis.com/maps/api/geocode/xml?address=Richmond&sensor=false" Then you will always get the result, but for some reason, through the code, it doesn't work sometimes.
Please help.