Android - Much Better Geo Location from just CellID/LAC
Digging a bit deeper!
The previous post that used the ZoneTag and Yahoo GeoCode API’s. Not this one!…Here are 3 screen shots for the following CellID/LAC combinations : (20442/6015, 53361/9800, 32981/6206)



As you may note, This sample has mush finer resolution/location.
Here’s some relevant code snippets:
public void browseTo(int cellid, int lac) throws Exception {
String url = "http://www.google.com/glm/mmap";
HttpURL httpURL = new HttpURL(url);
HostConfiguration host = new HostConfiguration();
host.setHost(httpURL.getHost(), httpURL.getPort());
HttpConnection connection = connectionManager.getConnection(host);
connection.open();
PostMethod postMethod = new PostMethod(url);
postMethod.setRequestEntity(new MyRequestEntity(cellid, lac));
postMethod.execute(new HttpState(), connection);
InputStream response = postMethod.getResponseBodyAsStream();
DataInputStream dis = new DataInputStream(response);
dis.readShort();
dis.readByte();
int code = dis.readInt();
if (code == 0) {
double lat = (double) dis.readInt() / 1000000D;
double lng = (double) dis.readInt() / 1000000D;
dis.readInt();
dis.readInt();
dis.readUTF();
Log.i("LocateMe", "Lat, Long: " + lat + "," + lng);
/**
* Start Google Maps and zoom into the lat/long
*/
ContentURI uri = ContentURI.create("geo:" + lat
+ "," + lng);
Intent intent = new Intent("android.intent.action.VIEW", uri);
startActivity(intent);
} else {
NotificationManager nm = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
nm.notifyWithText(100,
"Could not find lat/long information",
NotificationManager.LENGTH_SHORT, null);
}
connection.close();
}
private static class MyRequestEntity implements RequestEntity {
int cellId, lac;
public MyRequestEntity(int cellId, int lac) {
this.cellId = cellId;
this.lac = lac;
}
public boolean isRepeatable() {
return true;
}
public void writeRequest(OutputStream outputStream) throws
IOException {
DataOutputStream os = new DataOutputStream(outputStream);
os.writeShort(21);
os.writeLong(0);
os.writeUTF("fr");
os.writeUTF("Sony_Ericsson-K750");
os.writeUTF("1.3.1");
os.writeUTF("Web");
os.writeByte(27);
os.writeInt(0);
os.writeInt(0);
os.writeInt(3);
os.writeUTF("");
os.writeInt(cellId); // CELL-ID
os.writeInt(lac); // LAC
os.writeInt(0);
os.writeInt(0);
os.writeInt(0);
os.writeInt(0);
os.flush();
}
public long getContentLength() {
return -1;
}
public String getContentType() {
return "application/binary";
}
}
Download the sources and Application - LocateMe-3.0.zip
About this entry
You’re currently reading “Android - Much Better Geo Location from just CellID/LAC,” an entry on Show me the code!
- Published:
- 12.1.07 / 12am
- Category:
- Uncategorized
- Tags:
15 Comments
Jump to comment form | comments rss [?] | trackback uri [?]