views:

422

answers:

2

Hi,

Any ideas about how to do cell triangulation for Blackberry and J2ME phones? I know how to get the cell id but I couldn't do triangulation.

+1  A: 

If you can do an HTTP Post to an arbitray website, you can use Google's geolocation api.

Simply POST data in the following JSON format to https://www.google.com/loc/json Obviously you need to replace the data with you own.

{
  "version": "1.1.0",
  "cell_towers": [
    {
      "cell_id": "42",
      "location_area_code": 415,
      "mobile_country_code": 310,
      "mobile_network_code.": 410,
      "age": 0,
      "signal_strength": -60,
      "timing_advance": 5555
    },
    {
      "cell_id": "88",
      "location_area_code": 415,
      "mobile_country_code": 310,
      "mobile_network_code": 580,
      "age": 0,
      "signal_strength": -70,
      "timing_advance": 7777
    }
  ]
}

The will return you Google's estimate of the latitude/longitude on your location.

However, it seems that the Blackberry API only provides info on the currently connected cell, not other visible but unregistered cells. In this situation cannot do triangulation, as you (unsuprisingly) need three points to triangulate! However, a less accurate radial estimate of location is still possible.

You can still use the Google API for this, by providing only one tower, or you can use the Ericsson API if you choose. You might want to test with both and compare the accuracy. The Ericcson API is a similar JSON api to Google's, but only expects a single cell as input. A tutorial is available, but it boils down to a JSON request like this:

StringBuffer url = new StringBuffer();
url.append("http://cellid.labs.ericsson.net/json/lookup");
url.append("?cellid=").append(cell.getCellId());
url.append("&mnc=").append(cell.getMnc());
url.append("&mcc=").append(cell.getMcc());
url.append("&lac=").append(cell.getLac());
url.append("&key=").append(API_KEY);
try {
  byte[] data = getHttp(url.toString());
  if(data!=null) {
    JSONObject o = new JSONObject(new String(data));
    JSONObject pos = o.getJSONObject("position");
    this.longitude = pos.getDouble("longitude");
    this.latitude = pos.getDouble("latitude");
    this.accuracy = pos.getDouble("accuracy");
    this.cellName = pos.optString("name");
  }
} catch (IOException e) {
  e.printStackTrace();
} 
fmark
Hi! what is the min. number of cells for this functionality?
Max Gontar
Only one cell tower is required. However, accuracy will increase as more cell towers are added. The JSON result should include an accuracy estimation.
fmark
thanks for the info , but i don't know how to get data of 3 cells in blackberry , i can only get one cell data using :Integer.toString(GPRSInfo.getCellInfo().getCellId( ));//Retrieves the current cell ID.Integer.toString(GPRSInfo.getCellInfo().getLAC());//Retrieves the Location Area Code.Integer.toString(GPRSInfo.getCellInfo().getBSIC()) ;//Base Station Identity Code.
Galaxy
I've updated the answer to include Ericsson's API, which only expects a single cell id.
fmark
A: 

i have wrote the below code but it always return "{}" any help ?

public class Main {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    new Main();
}
private double longitude;
private double latitude;
private double accuracy;
private String cellName;

public Main() {
    try {
        JSONObject root = new JSONObject();
        root.put("version", "1.1.0");
        root.put("host", "maps.google.com");

        JSONArray cell_towers = new JSONArray();
        JSONObject cell_tower1 = new JSONObject();
        cell_tower1.put("cell_id", "42");
        cell_tower1.put("location_area_code", new Integer(415));
        cell_tower1.put("mobile_country_code", new Integer(310));
        cell_tower1.put("mobile_network_code", new Integer(410));
        cell_tower1.put("age", new Integer(0));
        cell_tower1.put("signal_strength", new Integer(-60));
        cell_tower1.put("timing_advance", new Integer(5555));
        cell_towers.add(cell_tower1);
        root.put("cell_towers", cell_towers);
        System.out.println(this.postHttp("https://www.google.com/loc/json", root));

    } catch (Exception ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }



}

private String postHttp(String url, JSONObject data) throws Exception {
    int c;
    StringBuilder respBuilder = new StringBuilder();
    if (url.length() == 0) {
        throw new Exception("WalletCM URL not set");
    }
    URL hp;
    try {
        hp = new URL(url);
    } catch (MalformedURLException ex) {
        throw new Exception("MalformedURLException :" + ex.getMessage());
    }
    URLConnection hpCon;
    try {
        hpCon = hp.openConnection();

        hpCon.setDoOutput(true);
        OutputStreamWriter wr = new OutputStreamWriter(hpCon.getOutputStream());
        String dd  = data.toJSONString();
        System.out.println(dd);
        wr.write(dd);
        wr.flush();
        int len = hpCon.getContentLength();
       if (len != 0) {
            InputStream input;

            input = hpCon.getInputStream();
            while (((c = input.read()) != -1)) {
                respBuilder.append((char) c);
            }
            input.close();
            return respBuilder.toString().trim();
        } else {
            throw new Exception("http resposne Content available.");
        }
    } catch (IOException ex) {
        throw new Exception("IOException :" + ex.getMessage());
    }


}

}

Galaxy
You should edit your question with these information instead of making an answer.
Michael B.