本文共 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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!