0

I have a device that sends me Mobile Country Code (MCC) Mobile Network Code (MNC) Location area code (LAC) and Cell ID of each closest mobile tower in my region. Google Latitude APP is using this info to detect my location. I would like to make my own app that could use same technique, but I can't find any Google API description.

There is a possibility to use OpenCellID for my purpose, but there are no CellIDs available for country where I live.

There are some posts where are outdated links to API which I need https://developers.google.com/gears/ and http://www.google.com/glm/mmap but seems like none of them work anymore.

2 Answers2

0

You can try using google Maps api:

https://developers.google.com/maps/?hl=es

They there's an option &sensor=true to detect if you are trying to get the latitude and longitude from a device.

aleation
  • 4,796
  • 1
  • 21
  • 35
  • Sorry, I guess I wasn't clear enough. Device is GPS Tracker, it sends all location parameters through GPRS to my server. As I understand, sensor parameter detects location from browser. – Kārlis Baumanis Oct 13 '12 at 10:45
  • I think the sensor parameter uses the smartphone's GPS, to use browser for location you must use the HTML5 geolocation API, wich is not needed actually for the sensor parameter. – aleation Oct 13 '12 at 11:32
0

Here is a PHP script that takes parameters mcc, mnc, lac and cid and returns latitude:longitude if a result is available, NOT_FOUND if no result is found. This makes use of the same Google API you've mentioned.

<?php


$data = 
"\x00\x0e". 
"\x00\x00\x00\x00\x00\x00\x00\x00". 
"\x00\x00". 
"\x00\x00". 
"\x00\x00". 
"\x1b". 
"\x00\x00\x00\x00". 
"\x00\x00\x00\x00". 
"\x00\x00\x00\x03".
"\x00\x00".
"\x00\x00\x00\x00". 
"\x00\x00\x00\x00". 
"\x00\x00\x00\x00". 
"\x00\x00\x00\x00". 
"\xff\xff\xff\xff". 
"\x00\x00\x00\x00"  
;
  $mcc = substr("00000000".dechex($_REQUEST["mcc"]),-8);
  $mnc = substr("00000000".dechex($_REQUEST["mnc"]),-8);
  $lac = substr("00000000".dechex($_REQUEST["lac"]),-8);
  $cid = substr("00000000".dechex($_REQUEST["cid"]),-8);


$init_pos = strlen($data);
$data[$init_pos - 38]= pack("H*",substr($mnc,0,2));
$data[$init_pos - 37]= pack("H*",substr($mnc,2,2));
$data[$init_pos - 36]= pack("H*",substr($mnc,4,2));
$data[$init_pos - 35]= pack("H*",substr($mnc,6,2));
$data[$init_pos - 34]= pack("H*",substr($mcc,0,2));
$data[$init_pos - 33]= pack("H*",substr($mcc,2,2));
$data[$init_pos - 32]= pack("H*",substr($mcc,4,2));
$data[$init_pos - 31]= pack("H*",substr($mcc,6,2));
$data[$init_pos - 24]= pack("H*",substr($cid,0,2));
$data[$init_pos - 23]= pack("H*",substr($cid,2,2));
$data[$init_pos - 22]= pack("H*",substr($cid,4,2));
$data[$init_pos - 21]= pack("H*",substr($cid,6,2));
$data[$init_pos - 20]= pack("H*",substr($lac,0,2));
$data[$init_pos - 19]= pack("H*",substr($lac,2,2));
$data[$init_pos - 18]= pack("H*",substr($lac,4,2));
$data[$init_pos - 17]= pack("H*",substr($lac,6,2));
$data[$init_pos - 16]= pack("H*",substr($mnc,0,2));
$data[$init_pos - 15]= pack("H*",substr($mnc,2,2));
$data[$init_pos - 14]= pack("H*",substr($mnc,4,2));
$data[$init_pos - 13]= pack("H*",substr($mnc,6,2));
$data[$init_pos - 12]= pack("H*",substr($mcc,0,2));
$data[$init_pos - 11]= pack("H*",substr($mcc,2,2));
$data[$init_pos - 10]= pack("H*",substr($mcc,4,2));
$data[$init_pos - 9]= pack("H*",substr($mcc,6,2));

if ((hexdec($cid) > 0xffff) && ($mcc != "00000000") && ($mnc != "00000000")) {
  $data[$init_pos - 27] = chr(5);
} else {
  $data[$init_pos - 24]= chr(0);
  $data[$init_pos - 23]= chr(0);
}

$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);
if (strlen($str) > 10) {
  $lat_tmp = unpack("l",$str[10].$str[9].$str[8].$str[7]);
  $lon_tmp = unpack("l",$str[14].$str[13].$str[12].$str[11]);
  $lon = $lon_tmp[1]/1000000;
  $lat = $lat_tmp[1]/1000000;
  echo $lat.":".$lon;


  }
   else{echo "NOT_FOUND";}

?>

Save the code as a php file (I've used locate.php in the example below), upload it to your web host and you can make a query as : http://yourwebhost.com/locate.php?mcc=XXX&mnc=XXX&lac=XXXXX&cid=XXXXXXXX You can then parse the response obtained to get latitude and longitude information.

akarthik10
  • 322
  • 1
  • 4
  • 11