google-maps - Google Api 未提供位置
问题描述
我正在使用 google API 在我的项目中获取位置。它有时会给出位置,但大多数时候它不会给出任何位置。从今天开始,它给服务器返回一个错误 403 禁止。当我在浏览器中点击 URL 时,它会给出位置。我没有为我的 API 使用任何密钥,这是否会导致此问题。
只是补充一下-我从我的 api 获取经纬度,然后从 google api 获取位置并将其存储在我的数据库中。
我正在做的是: -
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";
}
}
解决方案
添加您的 API 密钥
&key=yourkey
随着地图 API 的最新政策更新,我相信这一定是您遇到的情况......
也使用 https ... 仅允许通过 https
推荐阅读
- php - 只选择唯一数据的查询
- javascript - 如何将 javascript 加载的项目的值分配给模式页面 - Oracle Apex
- powershell - 如何使用 powershell 在应用程序模式下启动 Chromium Edge selenium webdriver
- python - 如何在 Jupyter 中修复“没有名为“blank_blank”的模块?
- regex - bigquery 的负前瞻替代方案
- javascript - 如何在 InpuTime 中传递带有参数的删除函数?
- webassembly - 是否可以在普通页面中嵌入跨域隔离的 iframe?
- android - 是否可以在应用程序类中删除房间数据库的数据?
- flutter - 我怎样才能在我的数据表中设计出这种标题或标题?
- spring-boot - 微服务中的事务管理