Notices


Reply
Thread Tools
BluesLee's Avatar
Posts: 411 | Thanked: 1,105 times | Joined on Jan 2010 @ Europe
#1
Hello,

i want to share a simple script in the hope that it might be useful for some of you. The script is very rudimentary and everything else than complete, robust or well written, just a quick hack which works for me.

What does the script do?
It reads cellid informations from your mobile using a specific dbus command ([1]). With this informations it enters a database and gets approximately your geo coordinates. For this you need to get a free API key from their webpage ([3]). In a final step this coordinates are used for a rough geo location using googles geo location API ([4]).

Is the script useful?
To be honest it is not very useful at least not for me I wrote it initially for profile switching purposes. Cellid informations are not enough to locate your position accurately. Nevertheless, it might be useful for other purposes.

Installation
  1. Download the attached file cellid2geolocation.txt to your N900 /home/user/ directory and rename it to cellid2geolocation.sh.
  2. Make the shell script executable:
    Code:
     chmod u+x cellid2geolocation.sh 
  3. Get your free API Key from http://location-api.com/ and insert the key you get via mail into the script.
  4. Execute the script:
    Code:
    ./cellid2geolocation.sh

The script itself
Code:

#!/bin/sh

# location-api.com key
KEY=

# get cellid codes via dbus command
# MCC:  Mobile Country Code;    MNC:    Mobile Network Code;
# LAC:  Local Area Code;        CELLID: Cellid;
EXPRESSION=`dbus-send --system --print-reply=literal --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.get_registration_status`
MCC=`echo $EXPRESSION | cut -f 10 -d " "`
MNC=`echo $EXPRESSION | cut -f 8 -d " "`
LAC=`echo $EXPRESSION | cut -f 4 -d " "`
CELLID=`echo $EXPRESSION | cut -f 6 -d " "`
echo "Cellid codes      : MCC=$MCC; MNC=$MNC; LAC=$LAC; CELLID=$CELLID"

# get corresponding geocoordinates via location-api.com database
wget -O geocoord.tmp "http://www.location-api.com/cell/get?key=$KEY&mcc=$MCC&mnc=$MNC&cellid=$CELLID&lac=$LAC" 1>/dev/null 2>&1
LAT=`grep lat geocoord.tmp | cut -f 7 -d " " | cut -f 2 -d "\""`
LON=`grep lon geocoord.tmp | cut -f 8 -d " " | cut -f 2 -d "\""`
echo "Geocoordinates    : LAT=$LAT; LON=$LON"

# get geolocation via google API
wget -O geoloc.tmp "http://maps.google.com/maps/api/geocode/json?latlng=$LAT,$LON&sensor=true" 1>/dev/null 2>&1
LOC=`grep formatted_address geoloc.tmp | head -1 | cut -f 4 -d "\""`
echo "Geolocation       : $LOC"

# Cleanup
rm -f geocoord.tmp geoloc.tmp


Further informations:
  1. http://lists.maemo.org/pipermail/mae...il/026004.html
  2. http://en.wikipedia.org/wiki/Mobile_Network_Code
  3. http://www.location-api.com/
  4. http://code.google.com/intl/eng-ENG/...verseGeocoding
Attached Files
File Type: txt cellid2geolocation.txt (1.2 KB, 161 views)

Last edited by BluesLee; 2011-04-22 at 10:50.
 

The Following 9 Users Say Thank You to BluesLee For This Useful Post:
Posts: 1,680 | Thanked: 3,685 times | Joined on Jan 2011
#2
oh boy, this is well sexingtons. I have been trying to work out how to get a geolocation to my bash scripts without resorting to all that pyton ***.
__________________
N900: One of God's own prototypes. A high-powered mutant of some kind never even considered for mass production. Too weird to live, and too rare to die.
 
Saturn's Avatar
Posts: 1,648 | Thanked: 2,122 times | Joined on Mar 2007 @ UNKLE's Never Never Land
#3
 
Saturn's Avatar
Posts: 1,648 | Thanked: 2,122 times | Joined on Mar 2007 @ UNKLE's Never Never Land
#4
Here is also some code that could be plugged if someone want to use other services.

This one is for the www.opencellid.org. It doesn't seem to have a restriction but the DB is quite limited and the results are even worse.
Code:
wget -O geocoord2.tmp "http://www.opencellid.org/cell/get?key=$KEY_OPENCELLID&mnc=$MNC&mcc=$MCC&lac=$LAC&cellid=$CELLID" 1>/dev/null 2>&1;
LATb=`grep lat geocoord2.tmp | cut -f 6 -d " " | cut -f 2 -d "\""`;
LONb=`grep lon geocoord2.tmp | cut -f 9 -d " " | cut -f 2 -d "\""`;
echo "Geocoordinates  : LAT=$LATb; LON=$LONb";
This one is for the https://labs.ericsson.com/apis/mobile-location/
The database is quite good but also has a trial period of 1000 requests.
Code:
wget -O geocoord3.tmp "http://cellid.labs.ericsson.net/xml/lookup?cellid=$CELLID&mnc=$MNC&mcc=$MCC&lac=$LAC&base=10&key=$KEY_ERICSSON" 1>/dev/null 2>&1;
LATc=`grep lat geocoord3.tmp | cut -f 6 -d \< | cut -f 2 -d \>`;
LONc=`grep lon geocoord3.tmp | cut -f 8 -d \< | cut -f 2 -d \>`;
echo "Geocoordinates  : LAT=$LATc; LON=$LONc";
If anyone has found a good one which is not a trial please let us know.
There is also a hidden google API for cellids but didn't tried it yet.

Hope it's usefull.
 

The Following 3 Users Say Thank You to Saturn For This Useful Post:
x61's Avatar
Posts: 932 | Thanked: 278 times | Joined on Sep 2009 @ Kentucky
#5
Does this obtain the location of the phone remotely via a computer?
 
Saturn's Avatar
Posts: 1,648 | Thanked: 2,122 times | Joined on Mar 2007 @ UNKLE's Never Never Land
#6
Originally Posted by x61 View Post
Does this obtain the location of the phone remotely via a computer?
Not as it is.

I'm investigating how it could be used in SMSCON to get some additional info or make it a background process (e.g. like the battery monitor) that logs in regular intervals the cell info.
Later could be plotted in a map and thus get a cheap in battery location tracking.

Very interesting stuff (in my opinion), just too little time to play..
 

The Following User Says Thank You to Saturn For This Useful Post:
Saturn's Avatar
Posts: 1,648 | Thanked: 2,122 times | Joined on Mar 2007 @ UNKLE's Never Never Land
#7
FYI, did some fiddling with the google APIs and made a poor man's GPS app.
See more here: http://talk.maemo.org/showthread.php?t=72497
 
Reply


 
Forum Jump


All times are GMT. The time now is 06:11.