我必须从地理编码更新我的数据库,以获得存储在数据库中的经度和纬度
为此我创建了一个控制台应用程序。每天我可以从谷歌每用户更新25000条记录,并且我从最近4到5天每天从不同的3台机器执行我的控制台。
但是我从今天开始获得OVER_QUERY_LIMIT状态,我无法更新数据库
我该怎么办呢?
以下是获取控制台经度 - 纬度的代码:
protected static void FindLocation(string strLocation, out string lat, out string lng, out string Output)
{
StreamWriter myWriter;
System.Net.HttpWebRequest geoRequest;
string googResponse;
googResponse = "";
lat = "";
lng = "";
Output = "";
string abc = "";
string strRequestURL;
strRequestURL = "https://maps.googleapis.com/maps/api/geocode/xml?address=" + strLocation + "&sensor=false";
try
{
geoRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(strRequestURL);
geoRequest.Method = "POST";
geoRequest.KeepAlive = true;
UTF8Encoding encoding = new UTF8Encoding();
byte[] bytes = encoding.GetBytes(strRequestURL);
geoRequest.ContentLength = bytes.Length;
using (Stream writeStream = geoRequest.GetRequestStream())
{
writeStream.Write(bytes, 0, bytes.Length);
writeStream.Close();
}
System.Net.HttpWebResponse geoResponse;
geoResponse = (System.Net.HttpWebResponse)geoRequest.GetResponse();
if (geoResponse != null)
{
XPathDocument document = new XPathDocument(geoResponse.GetResponseStream());
XPathNavigator navigator = document.CreateNavigator();
// get response status
XPathNodeIterator statusIterator = navigator.Select("/GeocodeResponse/status");
while (statusIterator.MoveNext())
{
if (statusIterator.Current.Value != "OK")
{
if (statusIterator.Current.Value == "OVER_QUERY_LIMIT")
{
}
Output = "Failed";
}
else
{
Output = statusIterator.Current.Value;
}
}
// get results
XPathNodeIterator resultIterator = navigator.Select("/GeocodeResponse/result");
while (resultIterator.MoveNext())
{
XPathNodeIterator geometryIterator = resultIterator.Current.Select("geometry");
while (geometryIterator.MoveNext())
{
XPathNodeIterator locationIterator = geometryIterator.Current.Select("location");
while (locationIterator.MoveNext())
{
XPathNodeIterator latIterator = locationIterator.Current.Select("lat");
while (latIterator.MoveNext())
{
lat = latIterator.Current.Value;
}
XPathNodeIterator lngIterator = locationIterator.Current.Select("lng");
while (lngIterator.MoveNext())
{
lng = lngIterator.Current.Value;
}
}
}
}
}
else
{
Output = "Failed";
}
}
catch (Exception ex)
{
Output = "Failed";
}
}