Show me the code! – By Davanum Srinivas

Web Services, Apache, Websphere, IBM, etc.

Android – Much Better Geo Location from just CellID/LAC

with 18 comments

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)

1


2


3


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

Written by Davanum Srinivas

December 1, 2007 at 12:37 am

Posted in Uncategorized

18 Responses

Subscribe to comments with RSS.

  1. [...] UPDATE: December 1, 2007 8 AM EST – Latest version is here [...]

  2. wow, great stuff.. how did you find out these request parameters in writeRequest() method?

    minstn

    December 1, 2007 at 4:52 pm

  3. [...] géolocalisation utilisant ce principe vient de voir le jour et c’est encore une création de Davanum. Bien sûr, il s’agit, comme toujours, plus d’une proof of concept que d’une [...]

  4. You are basically mapping the location of the cell tower, right? Even so, it is a big improvement over the previous version, which was the center of the zipcode where the tower was located.

    Now that you have precise locations for the tower, can you retrieve more cellids for nearby towers? If so, you could use triangulation to obtain a more accurate location.

    Even if not for Android, you could do this for the iPhone. It is possible to obtain multiple cellids and signal strengths.

    adk

    adk

    December 4, 2007 at 11:05 pm

  5. Also, where did you find the info on the http://www.google.com/glm/mmap service? Perhaps the have other useful functionality that could do some of the work for you?

    adk

    December 4, 2007 at 11:06 pm

  6. This is a very smart hack !

    Apparently, http://www.google.com/glm/mmap is the base URL of an hiden API, and the CellID and the LAC are valid Google Maps query parameters, aren’t they ?

    I don’t know Java, but it looks like we could use this URL as an API to convert cell towers metadata into geo coordinates like with Zonetag.

    kael

    December 5, 2007 at 3:02 pm

  7. [...] Locateme is a se of experimens by Davanum, who is also behind the twitter and gmail client, to create a geo location application using CellID/LAC combinations and the latest Google Maps location feature. [...]

  8. Do this a better way of localization? Does it better than GPS?

    Quauhtli Martinez

    December 7, 2007 at 10:33 am

  9. The url http://www.google.com/glm/mmap gives me a 404 error

    It has been changed or it works for you guys?

    Victor

    December 13, 2007 at 9:00 am

  10. Hi,

    This is a very interesting app. Could you please tell me how could I show multiple location on the same map.

    Vipin

    December 25, 2007 at 3:37 pm

  11. Hi,
    I tried your application, but it does not work for me!
    The last version (locateme 2.0) that use yahoo works fine with me, but for google, I got 404 for this url:

    http://www.google.com/glm/mmap

    Is it changed?

    Wael Shaban

    January 9, 2008 at 7:51 am

  12. I’ve tried it but it’s not working. Something change?

    Thanks, AR

    http://www.androidlocation.com/

    Andres Rormoser

    February 1, 2008 at 5:49 pm

  13. hi…,
    How can we find the location name(i.e. address/ street name) from cellid ,lac

    naveen

    February 5, 2008 at 7:04 am

  14. ho ho ho

    muluk

    April 5, 2008 at 10:23 am

  15. [...] Frank Brück (oder Neil Young?) für dieses Dokument und schlussendlich noch Davanum Srinivas für diesen kleinen Codefetzen. That’s it … hoffe ich. Eigentlich habe ich nur eine Konsolenversion, die ich vor [...]

  16. whatever

    May 9, 2008 at 10:21 am

  17. Several here complain that it doesn’t work anymore. What’s the beef?

    Papa Smurph

    July 2, 2008 at 2:37 pm

  18. What will be the base url is we want to do same using yahoo.

    sidh

    August 27, 2008 at 7:18 am


Leave a Reply