您的位置:首页 > 其它

手机基站定位源码

2013-04-25 14:25 253 查看
import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL;  /**  * Java利用CellID LAC调用Google接口获取经纬度例子  */
public class GoogleJson {     public static void main(String args[]) {          GoogleJson test = new GoogleJson();         URL url = null;         HttpURLConnection conn = null;         try {             url = new URL("http://www.google.com/loc/json");             conn = (HttpURLConnection) url.openConnection();             conn.setDoOutput(true);             conn.setRequestMethod("POST");              String json = test.getJson();             System.out.println(json);              conn.getOutputStream().write(json.getBytes());             conn.getOutputStream().flush();             conn.getOutputStream().close();             int code = conn.getResponseCode();             System.out.println("code " + code);             BufferedReader in = new BufferedReader(new InputStreamReader(                     conn.getInputStream()));             String inputLine;             inputLine = in.readLine();             System.out.println(inputLine);             in.close();             // 解析结果             // JSONObject result = new JSONObject(inputLine);             // JSONObject location = result.getJSONObject("location");             // JSONObject address = location.getJSONObject("address");              // System.out.println("city = " + address.getString("city"));             // System.out.println("region = " + address.getString("region"));
} catch (Exception e) {             e.printStackTrace();         } finally {             if (conn != null)                 conn.disconnect();         }     }      /**      * Google的官方例子      */
private String getJson() {         String json = "{ "
+ "\"version\": \"1.1.0\", "
+ "\"host\": \"maps.google.com\", "
// +                 // "\"access_token\": \"2:k7j3G6LaL6u_lafw:4iXOeOpTh1glSXe\", "
+ "\"home_mobile_country_code\": 460, "
+ "\"home_mobile_network_code\": 00, "
+ "\"radio_type\": \"gsm\", "
+ "\"carrier\": \"Vodafone\", "
+ "\"request_address\": true, "
+ "\"address_language\": \"zh_CN\", "
// + "\"location\": { "                 // + "\"latitude\": 51.0, " + "\"longitude\": -0.1 " + "}, "
+ "\"cell_towers\": [ "
+ "{ "
+ "\"cell_id\": 4912, "
+ "\"location_area_code\": 20516, "
+ "\"mobile_country_code\": 460, "
+ "\"mobile_network_code\": 00, "
+ "\"age\": 0, "
+ "\"signal_strength\": -60, "
+ "\"timing_advance\": 5555 "
+ "}"
// +", " + "{ " + "\"cell_id\": 88, "                 // + "\"location_area_code\": 415, "                 // + "\"mobile_country_code\": 310, "                 // + "\"mobile_network_code\": 580, " + "\"age\": 0, "                 // + "\"signal_strength\": -70, " + "\"timing_advance\": 7777 "                 // + "}"
+ "]"
//                +", " + "\"wifi_towers\": [ " + "{ " //                + "\"mac_address\": \"00:18:39:f4:29:01\", " //                + "\"signal_strength\": 8, " + "\"age\": 0 " + " }" //                // ", " + "{ " //                // + " \"mac_address\": \"01-23-45-67-89-ac\", " //                // + " \"signal_strength\": 4, " + " \"age\": 0 " + "}" //                + "] "

+ "}";         return json;     } }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息