B4A Library BGCellLocation v1.0 - Location using CellID

BGCellLocation v1.01 - Location using CellID

Hello everyone!
This library contains functions that return latitude and longitude coordinates using cellular tower information :sign0060:
It also contains a function to get neiboring cell IDs for getting more accurate position using triangulation, for instance.

- The following proceudre describes how to get the lat,lon of the currently associated cell tower:
It needs two parameters to work: Cell ID (cid) and Location Area Code (lac).
To extract them we can use the Reflection library:
Dim Obj1 As Reflector
Dim cid, lac As Int
Obj1.Target = Obj1.GetContext
Obj1.Target = Obj1.RunMethod2("getSystemService", "phone", "java.lang.String")
Obj1.Target = Obj1.RunMethod("getCellLocation") ' get a GsmCellLocation 
cid = Obj1.RunMethod("getCid") ' gsm cell id
lac = Obj1.RunMethod("getLac") ' gsm location area code
then we can use this data to get the coordinates:
Dim location as String
location = BGCell.getCellLocation(cid,lac)
Additional information is inside the library.
Please note: to get the coordinates this library uses an undocumented Google API (the same one used by Google Maps) which means it can break without notice.
Also note: the code will run on GUI thread! Using the Threading library is a good idea to keep the interface responsive.

Permissions used: "android.permission.ACCESS_COARSE_LOCATION" and "android.permission.INTERNET"
Tested on GSM device only. Users of CDMA devices please report your results.

Update 1.01
Added 2 new methods:
- getCellLocation2 returns lat,lon without decimal point. This is useful when using certain online APIs.
- getNeiboringCells returns a List with pairs of neighboring cell IDs and their Rssi separated by comma (,). Will return -1 as cell ID in UMTS mode.


- Benny


  • BGCellLocation 1.01.zip
    3.5 KB · Views: 779
Last edited:

Rafal Galewski

Licensed User
3 G problem

When we use in 3G GSM read value location in not stable.
Only work correct in 2 G set GSM.

When I have 3 G sometimes I have not found