急,google的基站定位无法访问
通过google来实现基站定位, 我已经获得设备的 cell-id 和 lac 号,然后上传到google的网址,两个方法我都试过了,但还是没有返回值,求指点。第一种方法:用POST方法上传到 http://www.google.com/glm/mmap,但是返回501错误。
Java代码如下:
public String getPosFromRes2(String reqJsonString){
String latLon = "";
String response = "";
try {
URL url = new URL("http://www.google.com/glm/mmap");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC-1.1");
conn.setRequestProperty("Content-Language","en-US");
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
byte[] request = reqJsonString.getBytes("UTF-8");
conn.setRequestProperty("Content-Length", Integer.toString(request!=null? request.length :0));
PrintWriter out = new PrintWriter(conn.getOutputStream());
out.print(reqJsonString); //request
System.out.println(reqJsonString);
out.flush();
//------------set BufferedReader to get response from google----- code: 400
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while((line=in.readLine())!=null){
response+="\n"+line;
}
System.out.println(response);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return response;
}
第二种方法:用POST上传JSON数据到 http://www.google.com/loc/json,但是返回400错误。
Java代码如下:
public String getPosFromRes(String reqJsonString) {
String latLon = "";
String response = "";
try {
URL url = new URL("http://www.google.com/loc/json");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
//POST request
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");
//System.out.println("open url");
//---------------set request property-----------------
conn.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC-1.1");
conn.setRequestProperty("Content-Language","en_US");
//conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Type", "application/json");
byte[] request = reqJsonString.getBytes("UTF-8");
conn.setRequestProperty("Content-Length", Integer.toString(request!=null? request.length :0));
//--------------send request------------
PrintWriter out = new PrintWriter(conn.getOutputStream());
out.print(reqJsonString); //request
System.out.println(reqJsonString);
out.flush();
//------------set BufferedReader to get response from google----- code: 400
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while((line=in.readLine())!=null){
response+="\n"+line;
}
System.out.println(response);
} catch (IOException e) {
System.out.println("发送POST请求出现异常!\n" + e);
e.printStackTrace();
}
return response;
}
请各位高人指点,谢谢啦! --------------------编程问答-------------------- 以前的帖子看过了,但还是有问题。。。 --------------------编程问答-------------------- 上goole 搜下api 在仔细看一下吧 --------------------编程问答-------------------- 除
补充:Java , J2ME