benlilaj / gears

Automatically exported from code.google.com/p/gears
0 stars 1 forks source link

return JSON error(400),Post cell information (CID,LAC,MCC,MNC...) to https://www.googleapis.com/geolocation/v1/geolocate?key=XXXXXXXXXXXXXXXXXX #1039

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Dear all,
   I post  cell information (CID,LAC,MCC,MNC...) to https://www.googleapis.com/geolocation/v1/geolocate?key=my_key,but it always return error 400,can you help me ? Thanks~

1)return error information as follows:
{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "parseError",
    "message": "Parse Error"
   }
  ],
  "code": 400,
  "message": "Parse Error"
 }
}
2)I implement as follows:
public class SCell{
    public int MCC;
    public int MNC;
    public int LAC;
    public int CID;
}
    private SItude getItude(SCell cell) throws Exception {
        SItude itude = new SItude();

        /** Using HttpClient of android by default*/
        HttpClient client = new DefaultHttpClient();
        /** using post'method */
        HttpPost post = new HttpPost("https://www.googleapis.com/geolocation/v1/geolocate?key=XXXXXXXXXXXXXXXXXX");
        try {
            /** POST JSON data structure */
            JSONObject holder = new JSONObject();
            holder.put("homeMobileCountryCode", cell.MCC);
            holder.put("homeMobileNetworkCode", cell.MNC);
            holder.put("radioType", "gsm");
            holder.put("carrier", "cmcc");

            JSONObject tower = new JSONObject();
            tower.put("cellId", cell.CID);
            tower.put("locationAreaCode", cell.LAC);
            tower.put("mobileCountryCode", cell.MCC);
            tower.put("mobileNetworkCode", cell.MNC);
            tower.put("age", 0);
            tower.put("signalStrength", -60);
            tower.put("timingAdvance", 15);

            JSONArray towerarray = new JSONArray();
            towerarray.put(tower);
            holder.put("cellTowers", towerarray);

            StringEntity query = new StringEntity(holder.toString());
            post.setEntity(query);

            /** send out JSON data,and return data */
            HttpResponse response = client.execute(post);
            HttpEntity entity = response.getEntity();
            BufferedReader buffReader = new BufferedReader(new InputStreamReader(entity.getContent()));
            StringBuffer strBuff = new StringBuffer();
            String result = null;
            while ((result = buffReader.readLine()) != null) {
                strBuff.append(result);
            }

            /** parse JSON data to get longitude and latitude */
            JSONObject json = new JSONObject(strBuff.toString());
            JSONObject subjosn = new JSONObject(json.getString("location"));

            itude.latitude = subjosn.getString("latitude");
            itude.longitude = subjosn.getString("longitude");

            Log.i("Itude", itude.latitude + itude.longitude);

        } catch (Exception e) {
            Log.e(e.getMessage(), e.toString());
            throw new Exception("error info :"+e.getMessage());
        } finally{
            post.abort();
            client = null;
        }

        return itude;
    } 

Original issue reported on code.google.com by arima.nj...@gmail.com on 8 Jun 2013 at 9:24

GoogleCodeExporter commented 9 years ago
The Google Gears API is no longer available - 
http://gearsblog.blogspot.com.au/2010/02/hello-html5.html

Original comment by stevebl...@google.com on 12 Jun 2013 at 7:20