微信

使用微信服务,更方便

职友集>Java面试题 > Blackberry 5.0中通过cellID获取本地方位

Blackberry 5.0中通过cellID获取本地方位

2015-06-02 06:30:01 阅读( 70 )

2289人 收藏本页

标签:Java面试题

public void cellID() {

int cellID = GPRSInfo.getCellInfo().getCellId();
int lac = GPRSInfo.getCellInfo().getLAC();

try {
String urlString2 = "http://www.google.com/glm/mmap";

/* Open a connection to Google Maps API */
ConnectionFactory connFact = new ConnectionFactory();
ConnectionDescriptor connDesc;
connDesc = connFact.getConnection(urlString2);

HttpConnection httpConn2;
httpConn2 = (HttpConnection)connDesc.getConnection();
httpConn2.setRequestMethod("POST");

/* Write some custom data to Google Maps API */
OutputStream outputStream2 = httpConn2.openOutputStream();//getOutputStream();
WriteDataGoogleMaps(outputStream2, cellID, lac);

/* Get the response */
InputStream inputStream2 = httpConn2.openInputStream();//getInputStream();
DataInputStream dataInputStream2 = new DataInputStream(inputStream2);

/* Interpret the response obtained */
dataInputStream2.readShort();
dataInputStream2.readByte();

int code = dataInputStream2.readInt();

if (code == 0) {
latitude = (double) dataInputStream2.readInt() / 1000000D;
longitude = (double) dataInputStream2.readInt() / 1000000D;

userLocation = new Coordinates(latitude,longitude,0);

dataInputStream2.readInt();
dataInputStream2.readInt();
dataInputStream2.readUTF();

} else {
System.out.println("Error obtaining Cell Id ");
}
outputStream2.close();
inputStream2.close();
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
}

/**
* Used to make the request to Google.
*/
private void WriteDataGoogleMaps(OutputStream out, int cellID, int lac)
throws IOException {
DataOutputStream dataOutputStream = new DataOutputStream(out);
dataOutputStream.writeShort(21);
dataOutputStream.writeLong(0);
dataOutputStream.writeUTF("en");
dataOutputStream.writeUTF("Android");
dataOutputStream.writeUTF("1.0");
dataOutputStream.writeUTF("Web");
dataOutputStream.writeByte(27);
dataOutputStream.writeInt(0);
dataOutputStream.writeInt(0);
dataOutputStream.writeInt(3);
dataOutputStream.writeUTF("");

dataOutputStream.writeInt(cellID);
dataOutputStream.writeInt(lac);

dataOutputStream.writeInt(0);
dataOutputStream.writeInt(0);
dataOutputStream.writeInt(0);
dataOutputStream.writeInt(0);
dataOutputStream.flush();
}

下一篇:java编程思想概括(第一章)---对象引论

上一篇:java使用split方法分隔字符串

亲~ 如果您有更好的答案 可在评论区发表您独到的见解。

您想查看更多的信息: 面试题