java wifi定位原理_使用基站、wifi实现定位
发布日期:2022-02-08 20:23:53 浏览次数:26 分类:技术文章

本文共 2699 字,大约阅读时间需要 8 分钟。

private Location callGear(ArrayList wifi,

ArrayList cellID) {

if (cellID == null) return null;

DefaultHttpClient client = new DefaultHttpClient();

HttpPost post = new HttpPost(

"http://www.google.com/loc/json");

JSONObject holder = new JSONObject();

try {

holder.put("version", "1.1.0");

holder.put("host", "maps.google.com");

holder.put("home_mobile_country_code", cellID.get(0).mobileCountryCode);

holder.put("home_mobile_network_code", cellID.get(0).mobileNetworkCode);

holder.put("radio_type", cellID.get(0).radioType);

holder.put("request_address", true);

if ("460".equals(cellID.get(0).mobileCountryCode))

holder.put("address_language", "zh_CN");

else

holder.put("address_language", "en_US");

JSONObject data,current_data;

JSONArray array = new JSONArray();

current_data = new JSONObject();

current_data.put("cell_id", cellID.get(0).cellId);

current_data.put("mobile_country_code", cellID.get(0).mobileCountryCode);

current_data.put("mobile_network_code", cellID.get(0).mobileNetworkCode);

current_data.put("age", 0);

array.put(current_data);

if (cellID.size() > 2) {

for (int i = 1; i 

data = new JSONObject();

data.put("cell_id", cellID.get(i).cellId);

data.put("location_area_code", cellID.get(0).locationAreaCode);

data.put("mobile_country_code", cellID.get(0).mobileCountryCode);

data.put("mobile_network_code", cellID.get(0).mobileNetworkCode);

data.put("age", 0);

array.put(data);

}

}

holder.put("cell_towers", array);

if (wifi.get(0).mac != null) {

data = new JSONObject();

data.put("mac_address", wifi.get(0).mac);

data.put("signal_strength", 8);

data.put("age", 0);

array = new JSONArray();

array.put(data);

holder.put("wifi_towers", array);

}

StringEntity se = new StringEntity(holder.toString());

Log.e("Location send", holder.toString());

post.setEntity(se);

HttpResponse resp = client.execute(post);

HttpEntity entity = resp.getEntity();

BufferedReader br = new BufferedReader(

new InputStreamReader(entity.getContent()));

StringBuffer sb = new StringBuffer();

String result = br.readLine();

while (result != null) {

Log.e("Locaiton reseive", result);

sb.append(result);

result = br.readLine();

}

data = new JSONObject(sb.toString());

data = (JSONObject) data.get("location");

Location loc = new Location(LocationManager.NETWORK_PROVIDER);

loc.setLatitude((Double) data.get("latitude"));

loc.setLongitude((Double) data.get("longitude"));

loc.setAccuracy(Float.parseFloat(data.get("accuracy").toString()));

loc.setTime(AppUtil.getUTCTime());

return loc;

} catch (JSONException e) {

return null;

} catch (UnsupportedEncodingException e) {

e.printStackTrace();

} catch (ClientProtocolException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

return null;

}

转载地址:https://blog.csdn.net/weixin_33132553/article/details/114119776 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:支付宝 java 签名算法_(支付宝)签名与验签
下一篇:matlab求二阶方阵对角化_梳理:矩阵对角化

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2024年04月05日 09时55分28秒