Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 1039 by [email protected]: return JSON error(400),Post cell information (CID,LAC,MCC,MNC...) to https://www.googleapis.com/geolocation/v1/geolocate?key=XXXXXXXXXXXXXXXXXX
http://code.google.com/p/gears/issues/detail?id=1039

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

--
You received this message because this project is configured to send all issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

--

--- You received this message because you are subscribed to the Google Groups "Gears Engineering Team" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to