Skip to content

Instantly share code, notes, and snippets.

@z0lope0z
Created November 28, 2014 03:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save z0lope0z/fe211d4c07975ff5f692 to your computer and use it in GitHub Desktop.
Save z0lope0z/fe211d4c07975ff5f692 to your computer and use it in GitHub Desktop.
Getting geo coordinates from old google maps API using Cell Tower ID, Location Area Code, Mobile Country Code, and Mobile Network Code
/**
* Shamelessly extracted from
* https://code.google.com/p/mwop/source/browse/sandbox/server/mwop-server/src/com/mwop/server/cellID/CellIDResolver.java?r=18
*/
public static Coordinate transform(int cellID, int lac, int mcc, int mnc) throws IOException {
URL providerAddress = new URL("http://www.google.com/glm/mmap");
HttpURLConnection connection = (HttpURLConnection) providerAddress.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.connect();
OutputStream outputStream = connection.getOutputStream();
writePlainData(outputStream, cellID, lac, mcc, mnc);
InputStream inputStream = connection.getInputStream();
DataInputStream dataInputStream = new DataInputStream(inputStream);
dataInputStream.readShort();
dataInputStream.readByte();
int code = dataInputStream.readInt();
if (code == 0) {
double lat = (double) dataInputStream.readInt() / 1000000D;
double lon = (double) dataInputStream.readInt() / 1000000D;
Coordinate coordinate = new Coordinate(lon, lat);
return coordinate;
} else {
return null;
}
}
protected static void writePlainData(OutputStream out, int cellID, int lac, int mcc, int mnc) throws IOException {
DataOutputStream dos = new DataOutputStream(out);
dos.writeShort(0x0E); // Fct code
dos.writeInt(0); // requesting 8 byte session
dos.writeInt(0);
dos.writeShort(0); // country code string
dos.writeShort(0); // client descriptor string
dos.writeShort(0); // version tag string
dos.writeByte(0x1B); // Fct code
dos.writeInt(0); // MNC?
dos.writeInt(0); // MCC?
dos.writeInt(3); // Radio Access Type (3=GSM, 5=UMTS)
dos.writeShort(0); // length of provider name
// provider name string
dos.writeInt(cellID); // CID
dos.writeInt(lac); // LAC
dos.writeInt(mnc); // MNC
dos.writeInt(mcc); // MCC
dos.writeInt(-1); // always -1
dos.writeInt(0); // rx level
dos.flush();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment