有人用过 map.google.com 吗?
在编程序,根据基站定位。
目前已经能正确获得基站的信息,如下:MCC: 460 mnc: 0 lac: 43042 cid: 26360769
但是用它向 google 查询经纬度的时候出错了,错误信息 e.Message 为 null。
会不会是因为 maps.google.com 被封掉的缘故啊?我用PC ping这个网站是不通的。
当然我也可以选择百度,但是百度需要开发者KEY,有点麻烦啊。
代码如下:
SItude itude = new SItude();
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://www.google.com/loc/json");
try{
JSONObject holder = new JSONObject();
holder.put("version", "1.1.0");
holder.put("host","maps.google.com");
holder.put("address_language", "zh_CN");
holder.put("request_address", true);
holder.put("radio_type", "gsm");
holder.put("carrier", "HTC");
JSONObject tower = new JSONObject();
tower.put("mobile_country_code", cell.MCC);
tower.put("mobile_network_code", cell.MNC);
tower.put("cell_id",cell.CID);
tower.put("location_area_code", cell.LAC);
JSONArray towerarray = new JSONArray();
towerarray.put(tower);
holder.put("cell_towers", towerarray);
StringEntity query = new StringEntity(holder.toString());
post.setEntity(query);
/** 发出POST数据并获取返回数据 */
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);
}
/** 解析返回的JSON数据获得经纬度 */
JSONObject json = new JSONObject(strBuff.toString());
JSONObject subjosn = new JSONObject(json.getString("location"));
itude.latitude = subjosn.getString("latitude");
itude.longitude = subjosn.getString("longitude");
} catch (Exception e){
Toast.makeText(getApplicationContext(), "获取经纬度出现错误:"+e.getMessage(), Toast.LENGTH_SHORT).show();
}