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:
then we can use this data to get the coordinates:
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.
Enjoy!
- Benny
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:
B4X:
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
B4X:
Dim location as String
location = BGCell.getCellLocation(cid,lac)
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.
Enjoy!
- Benny
Attachments
Last edited: