Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue Jun 26, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

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 [email protected] on 8 Jun 2013 at 9:24

@GoogleCodeExporter
Copy link
Author

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

Original comment by [email protected] on 12 Jun 2013 at 7:20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant