Sid
Sid

Reputation: 2862

How to convert Location Area Code to the address?

I want to get the tower locations, for this I am using TelephonyManager and I am getting the Location area code but this I want to convert in string to show the location.

    TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    GsmCellLocation cellLocation = (GsmCellLocation)telephonyManager.getCellLocation();

    int cellid= cellLocation.getCid();
    int celllac = cellLocation.getLac();


    Log.d("CellLocation", cellLocation.toString());
    Log.d("GSM CELL ID",  String.valueOf(cellid));
    Log.d("GSM Location Code", String.valueOf(celllac));

Here is the code, Where I am getting location area code, How can I convert it to string?

Please help thank you..

Upvotes: 0

Views: 2906

Answers (1)

Mick
Mick

Reputation: 25491

The LAC code is just an operator identifier for the location of an area ovf coverage - there is no algorithm etc to convert from it to a GPS location or street address.

There are databases that exist which contain a mapping cell ids to locations - for example, this is one of the best known:

You need to remember these are essentially just look up services so if the info is missing or wrong in their database you will not get the correct answer - i.e. it is not based on any algorithmic mapping from the LAC.

There is also a Google MAP's API which will allow you pass the mobile base station information and receive a GPS location in response:

This is a web service - you send a HTTPS POST message and get a response back. An example JSON for the request and response, based on the above link at the time of writing, make it fairly clear how it is used:

Request JSON:

{
  "homeMobileCountryCode": 310,
  "homeMobileNetworkCode": 410,
  "radioType": "gsm",
  "carrier": "Vodafone",
  "considerIp": "true",
  "cellTowers": [
    {
      "cellId": 42,
      "locationAreaCode": 415,
      "mobileCountryCode": 310,
      "mobileNetworkCode": 410,
      "age": 0,
      "signalStrength": -60,
      "timingAdvance": 15
    }
  ]
}

Response JSON:

{
  "location": {
    "lat": 51.0,
    "lng": -0.1
  },
  "accuracy": 1200.4
}

You do need an API key to use the service - see the link for the details.

Upvotes: 2

Related Questions