http://code.google.com/intl/zh-CN/apis/gears/geolocation_network_protocol.html
代码中是用GSM查询格式,如果是CDMA查询和GSM查询格式是一样的,只是需要修改4个地方:
1.radio_type 改为 “cdma”
2.cell_id 用 BID值替换
3.location_area_code用NID值替换
4.mobile_network_code用SID值替换
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;
}
}
分享到:
相关推荐
Google提供了API服务,允许开发者通过基站信息来获取对应的地理位置信息,如经纬度和实际地址。本项目就是针对这个功能进行封装,以C#编程语言实现,方便开发者快速集成和使用。 首先,基站码(Cell ID)是移动网络...
总的来说,这个项目提供了一种利用Google Maps API在C#环境中通过基站码获取地理位置的方法,同时也能将经纬度转换为可读的地址信息。开发这样的功能需要对网络请求、JSON解析以及Google Maps API有深入的理解。在...
在ASP.Net中,如果你需要获取特定的地理位置信息,如手机基站的cell-id(小区标识)和LAC(位置区码)对应的经纬度坐标,可以利用Google Geolocation API。这个API是一个网络协议,允许应用程序通过互联网查询设备的...
在Java编程环境下,我们可以利用Google提供的API和服务来实现这一功能。本文将深入探讨如何使用Java编写Google基站定位代码,以及相关的技术要点。 首先,基站定位的基础是通过获取到手机连接的基站信息,包括基站...
本文将深入探讨“google未公开API基站定位java版2013年4月可用”这一主题,以及相关的知识点。 首先,基站定位是通过利用手机与周围GSM(Global System for Mobile Communications)基站之间的通信来确定设备位置。...
基站定位是通过采集手机上的基站 ID 号(cellid)和其他的一些信息(MNC、MCC、LAC 等),然后通过网络访问一些定位服务,获取并返回对应的经纬度坐标。基站定位的精确度不如 GPS,但好处是能够在室内使用,只要网络...