Google 手机塔位置 API:已更改?
在过去的几个月里,当我们使用 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参数变化的记录。 还有什么可能发生的事情?这使用了 Google Gears,它已经被弃用了一段时间,但我在替代品上找不到任何 doco 可以找到手机信号塔。
有什么想法吗?
For the last few months I've been finding the locations of cell towers as we use their cellid and areaid, based on the following code:
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; }
}
}
The code worked flawlessly until sometime between one and two weeks ago, when it started returning error 400: Bad Request when it does the GetRequestStream().
My code hasn't changed.
I can't find any record of the API's parameters changing.
What else could be going on? This uses Google Gears, which has been deprecated for a while now, but I can't find any doco on a replacement that finds cell towers.
any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终把 Google 踢到了路边并使用了 OpenCellID:
I ended up kicking Google to the curb and using OpenCellID: