using System.Collections.Generic;
using System.Threading.Tasks;
public class GoogleCellId
private static byte[] GetPostData(UInt32 mcc, UInt32 mnc, UInt32 cellId, UInt32 lac)
0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
pd[0x11] = (byte)((mnc >> 24) & 0xFF);
pd[0x12] = (byte)((mnc >> 16) & 0xFF);
pd[0x13] = (byte)((mnc >> 8) & 0xFF);
pd[0x14] = (byte)((mnc >> 0) & 0xFF);
pd[0x15] = (byte)((mcc >> 24) & 0xFF);
pd[0x16] = (byte)((mcc >> 16) & 0xFF);
pd[0x17] = (byte)((mcc >> 8) & 0xFF);
pd[0x18] = (byte)((mcc >> 0) & 0xFF);
pd[0x27] = (byte)((mnc >> 24) & 0xFF);
pd[0x28] = (byte)((mnc >> 16) & 0xFF);
pd[0x29] = (byte)((mnc >> 8) & 0xFF);
pd[0x2a] = (byte)((mnc >> 0) & 0xFF);
pd[0x2b] = (byte)((mcc >> 24) & 0xFF);
pd[0x2c] = (byte)((mcc >> 16) & 0xFF);
pd[0x2d] = (byte)((mcc >> 8) & 0xFF);
pd[0x2e] = (byte)((mcc >> 0) & 0xFF);
pd[0x1f] = (byte)((cellId >> 24) & 0xFF);
pd[0x20] = (byte)((cellId >> 16) & 0xFF);
pd[0x21] = (byte)((cellId >> 8) & 0xFF);
pd[0x22] = (byte)((cellId >> 0) & 0xFF);
pd[0x23] = (byte)((lac >> 24) & 0xFF);
pd[0x24] = (byte)((lac >> 16) & 0xFF);
pd[0x25] = (byte)((lac >> 8) & 0xFF);
pd[0x26] = (byte)((lac >> 0) & 0xFF);
static public Tuple<int, decimal, decimal> GetLatLng(UInt16 mcc, UInt16 mnc, UInt32 cellId, UInt32 lac)
byte[] pd = GetPostData(mcc, mnc, cellId, lac);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri("http://www.google.com/glm/mmap"));
req.ContentLength = pd.Length;
req.ContentType = "application/binary";
Stream outputStream = req.GetRequestStream();
outputStream.Write(pd, 0, pd.Length);
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
byte[] ps = new byte[res.ContentLength];
while (totalBytesRead < ps.Length)
totalBytesRead += res.GetResponseStream().Read(ps, totalBytesRead, ps.Length - totalBytesRead);
Console.WriteLine("binary data:");
foreach (var binaryData in ps) {
Console.WriteLine(binaryData);
if (res.StatusCode == HttpStatusCode.OK)
short opcode1 = (short)(ps[0] << 8 | ps[1]);
int ret_code = (int)((ps[3] << 24) | (ps[4] << 16) | (ps[5] << 8) | (ps[6]));
Console.WriteLine("opcode1: " + opcode1 + ", opcode2: " + opcode2 + ", ret_code: " + ret_code);
double lat = ((double)((ps[7] << 24) | (ps[8] << 16) | (ps[9] << 8) | (ps[10]))) / 1000000;
double lon = ((double)((ps[11] << 24) | (ps[12] << 16) | (ps[13] << 8) | (ps[14]))) / 1000000;
return Tuple.Create(0, (decimal)lat, (decimal)lon);
Tuple.Create(-2, (decimal)0.0, (decimal)0.0);
return Tuple.Create(-1, (decimal)0.0, (decimal)0.0);
public static void Main()
var mmap = GoogleCellId.GetLatLng(UInt16.Parse("260"), UInt16.Parse("1"), UInt32.Parse(""), UInt32.Parse("11029"));
Console.WriteLine("MMap result " + mmap.ToString());