问题
I am using google API to get location in my project. It gives location sometimes but most of the time it does not give any location. and from today it is giving server return an error 403 forbidden. When i am hitting the URL in my browser it is giving location. I am not using any key for my API can it cause this issue.
Just to add- I get the lat and long from my api and then i get the location from google api and stores it in my database.
What i am doing is:-
public static string getGoogleLocationByLogLat(string log, string lat)
{
try
{
if (log == "")
{
log = "0.0";
}
if (lat == "")
{
lat = "0.0";
}
XmlTextReader xReader;
bool element = false;
string location = "", time, GL, parentEmail, respDateTime;
string parentElementName = "";
string childElementName = "";
string childElementValue = "", prmryCntact = "";
string url = "http://maps.google.com/maps/api/geocode/xml?latlng=" + lat + "," + log + "&sensor=true";
xReader = new XmlTextReader(url);
while (xReader.Read())
{
if (xReader.NodeType == XmlNodeType.Element)
{
if (element)
{
parentElementName = parentElementName + childElementName + "<br>";
}
element = true;
childElementName = xReader.Name;
}
else if (xReader.NodeType == XmlNodeType.Text | xReader.NodeType == XmlNodeType.CDATA)
{
element = false;
childElementValue = xReader.Value;
if (childElementName == "formatted_address")
{
location = childElementValue;
break;
}
}
}
if (location.Trim() == "")
{
location = "Location not found";
}
return location;
}
catch (Exception ex)
{
return "LOCATION NOT FOUND";
}
}
回答1:
Add your API key
&key=yourkey
With the latest policy updates to the maps api, i believe this must be the case that you're hitting...
Also use https ... It's permitted only over https
来源:https://stackoverflow.com/questions/51987226/google-api-is-not-giving-location