关于LBS

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) {

}

}




}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值