Show me the code! – By Davanum Srinivas

December 1, 2007

Android – Much Better Geo Location from just CellID/LAC

Filed under: Uncategorized — Davanum Srinivas @ 12:37 am

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

25 Comments »

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

    Pingback by Android - Poor man’s “My Location” (Show current cell location) « Show me the code! — December 1, 2007 @ 2:15 pm

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

    Comment by minstn — December 1, 2007 @ 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 […]

    Pingback by » Déjà une application de géolocalisation GSMAndroid After All — December 2, 2007 @ 1:49 pm

  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

    Comment by adk — December 4, 2007 @ 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?

    Comment by adk — December 4, 2007 @ 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.

    Comment by kael — December 5, 2007 @ 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. […]

    Pingback by This week's Android applications | Open Handset Magazine — December 6, 2007 @ 4:36 pm

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

    Comment by Quauhtli Martinez — December 7, 2007 @ 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?

    Comment by Victor — December 13, 2007 @ 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.

    Comment by Vipin — December 25, 2007 @ 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?

    Comment by Wael Shaban — January 9, 2008 @ 7:51 am

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

    Thanks, AR

    http://www.androidlocation.com/

    Comment by Andres Rormoser — February 1, 2008 @ 5:49 pm

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

    Comment by naveen — February 5, 2008 @ 7:04 am

  14. ho ho ho

    Comment by muluk — April 5, 2008 @ 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 […]

    Pingback by Google Maps MyLocation in C-Sharp | Sebbis Blog — April 25, 2008 @ 10:40 am

  16. Why this code looks so similar to this one:

    http://www.anddev.org/poor_mans_gps_-_celltowerid_-_location_area_code_-lookup-t257.html

    Comment by whatever — May 9, 2008 @ 10:21 am

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

    Comment by Papa Smurph — July 2, 2008 @ 2:37 pm

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

    Comment by sidh — August 27, 2008 @ 7:18 am

  19. i want that software to try …a cant download it……so pleas somebody give me a relevant link fr downloading….
    itz urgent…..
    or send t my id

    lavans4u@gmail.com

    Comment by lavan — July 15, 2009 @ 11:01 am

  20. Hello,

    This is not working in android 1.1. Do you have code which work in android 1.1 and android 1.5

    Comment by Kartik — July 28, 2009 @ 3:54 am

  21. Hi I am developing voip application for calling services http://www.callarc.com . I have few questions, is there anyway to extract cell ID via phone call. In otherwords is there any service that can allow me to lookup cell ID if I have the number of the caller?

    Comment by Patrick — March 16, 2010 @ 10:06 pm

  22. how to code if I want to know the LAC & Cell ID my friend

    Comment by GandoenG — May 20, 2011 @ 11:36 pm

  23. Hi, where can i download this?

    Comment by Tomislav — June 1, 2011 @ 10:33 am

  24. hello sir, our project is on identifying the user location basing on LAC and cell id. iam getting an error message that android package org packages does not exit. how should i include all those.

    Comment by B.Mohana priya — February 11, 2012 @ 12:58 am


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.