HowTo: Retrieve GSM cell coordinates

asked 2014-02-06 03:38:10 +0200

marsch gravatar image

updated 2014-02-06 10:44:05 +0200

foss4ever gravatar image

I've been hacking some code together to retrieve geodata from a given GSM cell. In case anybody is looking for similar stuff, here you go:

#!/bin/sh

# Retrieve cell ID code via DBUS
# Idea from http://talk.maemo.org/showthread.php?t=72419

KEY="dxxxxxxx6-d7cb-42e2-a1f3-253axxxxxx9c"
TMP=`/bin/mktemp`
/bin/dbus-send --system --print-reply=literal --type=method_call --dest=org.ofono /ril_0 org.ofono.NetworkRegistration.GetProperties > $TMP

for INFO in LocationAreaCode CellId MobileCountryCode MobileNetworkCode; do
   eval $INFO=`/bin/grep $INFO $TMP | /bin/awk -F ' [^0-9]+' '{print $2 $3}' | /bin/awk '{print $NF}'`
done

echo "Cell ID codes"
echo "  MCC: $MobileCountryCode"
echo "  MNC: $MobileNetworkCode"
echo "  LAC: $LocationAreaCode"
echo "  CELL:$CellId"

URL="http://www.opencellid.org/cell/get?key=$KEY&mnc=$MobileNetworkCode&mcc=$MobileCountryCode&lac=$LocationAreaCode&cellid=$CellId"
/usr/bin/curl -o $TMP $URL 1>/dev/null 2>&1

echo ""
if /bin/grep fail $TMP >/dev/null; then
  echo "Coordinates could not be retrieved."
else
  LAT=`/bin/grep lat $TMP | /bin/awk -F '"' '{print  $2}'` 
  LON=`/bin/grep lon $TMP | /bin/awk -F '"' '{print  $4}'` 
  echo "Geo coordinates"
  echo "  LAT: $LAT"
  echo "  LON: $LON"
fi

/bin/rm -f $TMP
edit retag flag offensive close delete

Comments

Nice! How accurate is it / how complete is the opencellid db? And, could that be done from Qt/C++ with current Harbour Q/A-rules?

foss4ever ( 2014-02-06 10:10:36 +0200 )edit
1

Thanks for sharing. I slightly edited it to make it obvious that this is not the question but already the answer.

jgr ( 2014-02-06 10:37:08 +0200 )edit

re-tag: changed programming to development(as it is quite frequently used for similar topics)

foss4ever ( 2014-02-06 10:46:21 +0200 )edit
3

Thanks for renaming/tagging. Have a look at http://www.opencellid.org/ regarding the coverage in your area.

Building a fully fledged app would of course be conceivable, however such an app should also integrate cell logging including upload to opencellid, in order to support the project.

But I'm not too confident that I'll be able to rip off the necessary time resources in the short term.

marsch ( 2014-02-06 11:12:46 +0200 )edit
1

@marsch Thanks for the info.. gotta check that site out.. In development terms I was just wondering which Qt-APIs would be required to do the same that's now done with that dbus-call, and does Harbour Q/A admit 3rd-party app to use those. Any info on this?

foss4ever ( 2014-02-06 11:53:40 +0200 )edit