谷歌手机塔定位API:改变



在过去的几个月里,我一直在寻找手机信号塔的位置,因为我们使用他们的手机和区域,基于以下代码:

   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; }
            }
        }

代码一直工作得很完美,直到一到两周前,当它执行GetRequestStream()时开始返回错误400:错误请求。

我的代码没有改变。我找不到任何API参数变化的记录。还会发生什么呢?这使用了Google Gears,它已经被弃用一段时间了,但是我找不到任何关于替换的文档,可以找到蜂窝塔。

任何想法?

我最终把Google踢到路边,使用OpenCellID:

public CellTowerPOCO GetCellInfo_OpenCellID(string lac, string mnc, string mcc, string cellID)
{
    try
    {
        HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(string.Format("http://www.opencellid.org/cell/get?mcc={0}&mnc={1}&cellid={2}&lac={3}",mcc,mnc,cellID,lac));
        HttpWebResponse webresponse;
        webresponse = (HttpWebResponse)myReq.GetResponse();
        //Encoding enc = System.Text.Encoding.UTF8;

        StreamReader loResponseStream = new StreamReader(webresponse.GetResponseStream());
        string Response = loResponseStream.ReadToEnd();
        loResponseStream.Close();
        webresponse.Close();

        CellTowerPOCO Mycell = new CellTowerPOCO();
        XmlDocument xdoc = new XmlDocument();
        xdoc.LoadXml(Response);
        Mycell.location.latitude = xdoc.ChildNodes[1].FirstChild.Attributes["lat"].Value;
        Mycell.location.longitude = xdoc.ChildNodes[1].FirstChild.Attributes["lon"].Value;
        Mycell.Mcc = mcc;
        Mycell.CellID = cellID;
        Mycell.Mnc = mnc;
        //MessageBox.Show(xdoc.ChildNodes[0].InnerText);
        return Mycell;
    }
    catch (Exception ex)
    {
        string strErr = ex.Message;
        if (ex.InnerException != null)
        {
            strErr += ": " + ex.InnerException.Message;
        }
        MessageBox.Show(strErr);
        return new CellTowerPOCO();
    }
}