Ok, I think I’ve reach that point where I need to stop and catch up on lost sleep …
There seems to be a lot of recent interest in location based technology, and now with the latest MyLocation functionality in Google Maps for Mobile (GMM), it wont be long before businesses start chomping at the bit to get their products/services mapped to make it easy for Joe Public to navigate to a shop or restaurant, using just a humble GSM mobile phone without GPS fitted.
So I thought I’d join this race and get myself up to speed with the latest tools and development ideas – hence the insomnia and radio silence (haha pun not intended!). Anyway, I’ve written a number of PHP scripts to geocode LAC/CID data from the RIL module on my Windows Mobile WM6 PDA into a seachable AJAX google map – in English, this means that my PDA is continuously updating my webserver with the GSM cell tower information which I am currently connected to, and I then turn this into geogaphical references (Latitude & Longitude) which are plottable on Google Map. And just for fun, I nicked someone’s code to reverse geocode the Lat/Long into Street Name, Town, Postcode, Country etc … click here to see my last reported position, click on the pushpin to get details of timestamp. Next step, a J2ME app that will work on most GSM phones to query the RIL for cell data, do some triagulation onsignal strength to determine the hotspot (cell towers don’t provide GPS accuracy) and update a MySQL database with an ‘invisible’ http session. Now that will be an interesting project …
Those of you who want to try this out, I’ve also knocked up a prototype script which you can access from http://fiftyone.no-ip.org/files/geocodecelltower3.php?lac=10&cid=16701 – you just need to put in the LAC (Local Area Code) and CID (CellID) – if you know what these are …
Happy locating!
April 28, 2009 at 6:59 pm
Do you have the PHP script that can do this? I need to build a prototype LBS service. It’s hard to get a database with cell-id’s
April 29, 2009 at 10:00 pm
here you go … get yourself a google maps API key for your site and replace where it says XXXXX. to invoke this PHP, go to
http://mydomain.com/geocodecelltower3.php?lac=10&cid=16701
you will also need “greversegeocoder.js” which you can google for …
<?php
// history
// v0.3 – with reverse geocoding of lat/long to street, postcode
// v0.2 – using javascript & ajax search
// v0.1 – original using javascript class
$data =
“\x00\x15″. // Function Code?
“\x00\x00\x00\x00\x00\x00\x00\x00″. //Session ID?
“\x00\x02\x66\x72″. // Contry Code
“\x00\x12\x53\x6f\x6e\x79\x5f\x45\x72\x69\x63\x73\x73\x6f\x6e\x2d\x4b\x37\x35\x30″.
“\x00\x05\x31\x2e\x33\x2e\x31″. // Version
“\x00\x03\x57\x65\x62″. // Web
“\x1b”. // Op Code?
“\x00\x00\x00\x00″. // MNC
“\x00\x00\x00\x00″. // MCC
“\x00\x00\x00\x03″.
“\x00\x00″.
“\x00\x00\x00\x00″. //CID
“\x00\x00\x00\x00″. //LAC
“\x00\x00\x00\x00″. // ??
“\x00\x00\x00\x00″. // ??
“\x00\x00\x00\x00″. // ??
“\x00\x00\x00\x00″ // ??
;
$hexlac = substr(“0000″.dechex($_REQUEST["lac"]),-4);
$hexcid = substr(“0000″.dechex($_REQUEST["cid"]),-4);
// echo “LAC=$hexlac CID=$hexcid”;
$data[63]= pack(“H*”,substr($hexcid,0,2));
| (ord($str[10]))) / 1000000;
| (ord($str[14]))) / 1000000;
$data[64]= pack(“H*”,substr($hexcid,2,2));
$data[67]= pack(“H*”,substr($hexlac,0,2));
$data[68]= pack(“H*”,substr($hexlac,2,2));
$context = array (
‘http’ => array (
‘method’ => ‘POST’,
‘header’=> “Content-type: application/binary\r\n”
. “Content-Length: ” . strlen($data) . “\r\n”,
‘content’ => $data
)
);
$xcontext = stream_context_create($context);
$str=file_get_contents(“http://www.google.com/glm/mmap”,FALSE,
$xcontext);
$lat = ((ord($str[7]) << 24) | (ord($str[8]) << 16) | (ord($str[9]) <<
$lon = ((ord($str[11]) << 24) | (ord($str[12]) << 16) | (ord($str[13])
<<
//echo “Lat=$lat Lon=$lon”;
// exit script if cannot geocode cell e.g. not on google’s database
if ($lat == 0 and $lon == 0)
exit(‘geocodeCellTower: cannot determine cell tower location from cell LAC: ‘ . $_REQUEST["lac"] . ‘, ‘ . ‘CID: ‘ . $_REQUEST["cid"]);
$addr = $lat . ‘,’ . $lon;
// set the pushpin info
$desc = ‘Cell Tower: ‘ . $hexlac . ‘, ‘ . $hexcid . ‘ with map co-ordinates reading ‘ .
‘Lat: ‘ . $lat .’, ‘ . ‘Long: ‘ . $lon;
?>
geocodecelltower v0.3
@import url(“http://www.google.com/uds/css/gsearch.css”);
@import url(“http://www.google.com/uds/solutions/localsearch/gmlocalsearch.css”);
#map {
border : 1px solid #979797;
width : 75%;
height : 400px;
}
//<![CDATA[
function load() {
if (GBrowserIsCompatible()) {
// Create and Center a Map
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(, ), 15);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
var point = new GLatLng(, );
map.addOverlay(new GMarker(point));
// alert(" is near "+ "" + " on cell , - last updated @ ");
/* Metal Mode */
// set up pins, use the metalset
var pins = new Array();
pins["kml"] = “metalblue”;
pins["local"] = “metalred”;
var labels = new Array();
labels["kml"] = “metalblue”;
labels["local"] = “metalred”;
// then in options pass:
// pins : pins, labels : labels
/**/
var options = {
listingTypes : GlocalSearch.TYPE_BLENDED_RESULTS,
Xpins : pins,
Xlabels : labels
}
map.addControl(new google.maps.LocalSearch(options));
var reversegeocoder = new GReverseGeocoder(map);
GEvent.addListener(reversegeocoder, “load”,
function(placemark) {
alert(“You are near “+ placemark.address + ” on “);
}
);
reversegeocoder.reverseGeocode(new GLatLng(, ));
}
}
GSearch.setOnLoadCallback(load);
//]]>