/ Published in: Java
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
public void cellID() { int cellID = GPRSInfo.getCellInfo().getCellId(); int lac = GPRSInfo.getCellInfo().getLAC(); try { /* 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 */ WriteDataGoogleMaps(outputStream2, cellID, lac); /* Get the response */ /* 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 { } outputStream2.close(); inputStream2.close(); } } /** * Used to make the request to Google. */ 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(); }