在过去的几个月里,我一直在根据以下代码使用它们的 cellid 和 areaid 来查找蜂窝塔的位置:
public class GoogleService
{
public GoogleCell GetCellInfo(string lac, string mnc, string mcc, string cellID)
{
try
{
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("https://www.google.com/loc/json");
myReq.Method = "POST";
myReq.ContentType = "application/jsonrequest";
string postData = "{\"cell_towers\": [{\"location_area_code\": \"" + lac + "\", \"mobile_network_code\": \"" + mnc + "\", \"cell_id\": \"" + cellID + "\", \"mobile_country_code\": \"" + mcc + "\"}], \"version\": \"1.1.0\", \"request_address\": \"true\"}";
myReq.ContentLength = postData.Length;
StreamWriter stOut = new StreamWriter(myReq.GetRequestStream(), System.Text.Encoding.ASCII);
stOut.Write(postData);
stOut.Close();
HttpWebResponse webresponse;
webresponse = (HttpWebResponse)myReq.GetResponse();
Encoding enc = System.Text.Encoding.UTF8;
StreamReader loResponseStream = new StreamReader(webresponse.GetResponseStream(), enc);
string Response = loResponseStream.ReadToEnd();
loResponseStream.Close();
webresponse.Close();
GoogleCell Mycell = JsonConvert.DeserializeObject<GoogleCell>(Response);
return Mycell;
}
catch (Exception ex)
{
string strErr = ex.Message;
if (ex.InnerException != null)
{
strErr += ": " + ex.InnerException.Message;
}
MessageBox.Show(strErr);
return new GoogleCell();
}
}
}
public class GoogleCell
{
public GoogleCell() { }
public GoogleCell(string mnc, string mcc, string lac)
{
this.Mnc = mnc;
this.Mcc = mcc;
this.Lac = lac;
}
public string Mnc { get; set; }
public string Mcc { get; set; }
public string Lac { get; set; }
public string CellID { get; set; }
public Location location { get; set; }
public class Location
{
public Location() { }
public Location(string latitude, string longitude)
{
this.latitude = latitude;
this.longitude = longitude;
}
public string latitude { get; set; }
public string longitude { get; set; }
public Address address { get; set; }
public class Address
{
public Address() { }
public string country { get; set; }
public string country_code { get; set; }
public string city { get; set; }
public string region { get; set; }
public string street { get; set; }
public string street_number { get; set; }
public string postal_code { get; set; }
}
}
该代码完美运行,直到一到两周前的某个时间,它开始返回错误 400:执行 GetRequestStream() 时出现错误请求。
我的代码没有改变。我找不到任何 API 参数更改的记录。还有什么可能发生的?这使用了谷歌齿轮,它已经被弃用了一段时间,但我找不到任何能找到手机信号塔的替代品。
有任何想法吗?