public class LbsActivity implements View.OnClickListener {
private Activity act;
private TelephonyManager tm;
private TextView t;
private Button bu;
GsmCellLocation gsc;
public LbsActivity(Activity act){
this.act= act;
tm = (TelephonyManager) act.getSystemService(Context.TELEPHONY_SERVICE);
gsc = (GsmCellLocation) tm.getCellLocation();
}
public void show(){
act.setContentView(R.layout.aa);
t = (TextView) act.findViewById(R.id.t);
bu = (Button) act.findViewById(R.id.button1);
bu.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
int cid = gsc.getCid();
int lac = gsc.getLac();
int mcc = Integer.valueOf(tm.getNetworkOperator().substring(0,
3));
int mnc = Integer.valueOf(tm.getNetworkOperator().substring(3,
5));
String getNum = "";
getNum += ("cid:" + cid + "\n");
getNum += ("cid:" + lac + "\n");
getNum += ("cid:" + mcc + "\n");
getNum += ("cid:" + mnc + "\n");
try {
JSONObject obj = new JSONObject();
obj.put("version", "1.1.0");
obj.put("host", "maps.google.com");
obj.put("request_address", true);
if (mcc == 460) {
obj.put("address_language", "zh_CN");
} else {
obj.put("address_language", "en_US");
}
JSONArray jarra = new JSONArray();
JSONObject jdata = new JSONObject();
jdata.put("cell_id", cid);
jdata.put("location_area_code", lac);
jdata.put("mobile_country_code", mcc);
jdata.put("mobile_network_code", mnc);
jarra.put(jdata);
obj.put("cell_towers", jarra);
DefaultHttpClient hc = new DefaultHttpClient();
HttpPost post = new HttpPost(
"http://www.google.com/loc/json");
StringEntity se = new StringEntity(obj.toString());
Log.e("OBJ", obj.toString());
post.setEntity(se);
HttpResponse resp = hc.execute(post);
BufferedReader bf = null;
if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
bf = new BufferedReader(new InputStreamReader(resp
.getEntity().getContent()));
StringBuffer sb = new StringBuffer();
String result = bf.readLine();
while (result != null) {
sb.append(result);
result = bf.readLine();
}
}
} catch (Exception e) {
}
}
}
关于LBS
最新推荐文章于 2024-10-12 17:14:32 发布