从cellid、lac、MCC、MNC获取c#中的纬度和经度,用于控制台或wpf应用程序

从cellid、lac、MCC、MNC获取c#中的纬度和经度,用于控制台或wpf应用程序,c#,wpf,api,console-application,C#,Wpf,Api,Console Application,我正在创建一个获取cellid、MCC、MNC和LAC的系统,我想使用opencellid从这些信息中获取纬度和经度,我在互联网上找不到资源,所以我不知道从哪里开始。如果你能帮我找到如何做到这一点,或者给我一个替代的解决方案,从这些信息中找到纬度和经度,那就太好了。谢谢您可以在此处找到API信息: 检查下面的代码我希望这有帮助:) 使用系统; 使用System.Collections.Generic; 使用System.Linq; 使用系统文本; 使用System.IO; Net系统; 命名空间

我正在创建一个获取cellid、MCC、MNC和LAC的系统,我想使用opencellid从这些信息中获取纬度和经度,我在互联网上找不到资源,所以我不知道从哪里开始。如果你能帮我找到如何做到这一点,或者给我一个替代的解决方案,从这些信息中找到纬度和经度,那就太好了。谢谢

您可以在此处找到API信息:

检查下面的代码我希望这有帮助:)

使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.IO;
Net系统;
命名空间控制台应用程序1
{
公共类谷歌地图
{
静态字节[]PostData(int-MCC、int-MNC、int-LAC、int-CID)
{
/*shortCID参数遵循启发式经验:
*有时,UMTS CID是从原始GSM CID(较低的4个十六进制数字)生成的
*RNC-ID左移到上面4位。
*/
字节[]pd=新字节[]{
0x00,0x0e,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,
0x00,0x00,
0x00,0x00,
0x1b,
0x00,0x00,0x00,0x00,//偏移量0x11
0x00,0x00,0x00,0x00,//偏移量0x15
0x00,0x00,0x00,0x00,//偏移量0x19
0x00,0x00,
0x00,0x00,0x00,0x00,//偏移量0x1f
0x00,0x00,0x00,0x00,//偏移量0x23
0x00,0x00,0x00,0x00,//偏移量0x27
0x00,0x00,0x00,0x00,//偏移量0x2b
0xff,0xff,0xff,0xff,
0x00,0x00,0x00,0x00
};
控制台写入线(pd长度);
bool-isUMTSCell=((Int64)CID>65535);
/*if(shortCID)
CID&=0xFFFF;/*尝试使用
GSM CID部件*/
如果((Int64)CID>65536)/*GSM:4个十六进制数字,UTMS:6个十六进制数字
数字*/
pd[0x1c]=5;
其他的
pd[0x1c]=3;
pd[0x11]=(字节)((MNC>>24)和0xFF);
pd[0x12]=(字节)((MNC>>16)和0xFF);
pd[0x13]=(字节)((MNC>>8)和0xFF);
pd[0x14]=(字节)((MNC>>0)和0xFF);
pd[0x15]=(字节)((MCC>>24)和0xFF);
pd[0x16]=(字节)((MCC>>16)和0xFF);
pd[0x17]=(字节)((MCC>>8)和0xFF);
pd[0x18]=(字节)((MCC>>0)和0xFF);
pd[0x27]=(字节)((MNC>>24)和0xFF);
pd[0x28]=(字节)((MNC>>16)和0xFF);
pd[0x29]=(字节)((MNC>>8)和0xFF);
pd[0x2a]=(字节)((MNC>>0)和0xFF);
pd[0x2b]=(字节)((MCC>>24)和0xFF);
pd[0x2c]=(字节)((MCC>>16)和0xFF);
pd[0x2d]=(字节)((MCC>>8)和0xFF);
pd[0x2e]=(字节)((MCC>>0)和0xFF);
pd[0x1f]=(字节)((CID>>24)和0xFF);
pd[0x20]=(字节)((CID>>16)和0xFF);
pd[0x21]=(字节)((CID>>8)和0xFF);
pd[0x22]=(字节)((CID>>0)和0xFF);
pd[0x23]=(字节)((LAC>>24)和0xFF);
pd[0x24]=(字节)((LAC>>16)和0xFF);
pd[0x25]=(字节)((LAC>>8)和0xFF);
pd[0x26]=(字节)((LAC>>0)和0xFF);
返回pd;
}
静态公共字符串[]GetLatLng(int-MCC、int-MNC、int-LAC、int-CID)
{
字符串[]结果=新字符串[2];
尝试
{
字符串url=”http://www.google.com/glm/mmap";
HttpWebRequest req=(HttpWebRequest)WebRequest.Create(
新Uri(url));
请求方法=“POST”;
字节[]pd=PostData(MCC、MNC、LAC、CID);
req.ContentLength=pd.Length;
req.ContentType=“应用程序/二进制”;
Stream outputStream=req.GetRequestStream();
outputStream.Write(pd,0,pd.Length);
outputStream.Close();
HttpWebResponse res=(HttpWebResponse)req.GetResponse();
byte[]ps=新字节[res.ContentLength];
int totalBytesRead=0;
while(总字节读取//对于(int i=0;iIt最好避免只提供链接的答案。如果可以的话,尝试从链接中包含一些相关信息。
using System;
using System.Collections.Generic;
using System.Linq;

using System.Text;
using System.IO;
using System.Net;

namespace ConsoleApplication1
{
    public class GoogleMapsApi
    {
        static byte[] PostData(int MCC, int MNC, int LAC, int CID)
        {

        /* The shortCID parameter follows heuristic experiences:

         * Sometimes UMTS CIDs are build up from the original GSM CID (lower 4 hex digits)

         * and the RNC-ID left shifted into the upper 4 digits.

         */

        byte[] pd = new byte[] {

    0x00, 0x0e,

    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

    0x00, 0x00,

    0x00, 0x00,

    0x00, 0x00,

    0x1b,

    0x00, 0x00, 0x00, 0x00, // Offset 0x11

    0x00, 0x00, 0x00, 0x00, // Offset 0x15

    0x00, 0x00, 0x00, 0x00, // Offset 0x19

    0x00, 0x00,

    0x00, 0x00, 0x00, 0x00, // Offset 0x1f

    0x00, 0x00, 0x00, 0x00, // Offset 0x23

    0x00, 0x00, 0x00, 0x00, // Offset 0x27

    0x00, 0x00, 0x00, 0x00, // Offset 0x2b

    0xff, 0xff, 0xff, 0xff,

    0x00, 0x00, 0x00, 0x00

};
        Console.WriteLine(pd.Length);

        bool isUMTSCell = ((Int64)CID > 65535);

        /*    if (shortCID)

                CID &= 0xFFFF;      /* Attempt to resolve the cell using the

                            GSM CID part */

        if ((Int64)CID > 65536) /* GSM: 4 hex digits, UTMS: 6 hex

                        digits */

            pd[0x1c] = 5;

        else

            pd[0x1c] = 3;

        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)((CID >> 24) & 0xFF);

        pd[0x20] = (byte)((CID >> 16) & 0xFF);

        pd[0x21] = (byte)((CID >> 8) & 0xFF);

        pd[0x22] = (byte)((CID >> 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);

        return pd;

    }

    static public string[] GetLatLng(int MCC, int MNC, int LAC, int CID)
    {

        string[] result = new string[2];

        try
        {

            String url = "http://www.google.com/glm/mmap";

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(

                new Uri(url));

            req.Method = "POST";

            byte[] pd = PostData(MCC, MNC, LAC, CID);

            req.ContentLength = pd.Length;

            req.ContentType = "application/binary";

            Stream outputStream = req.GetRequestStream();

            outputStream.Write(pd, 0, pd.Length);

            outputStream.Close();

            HttpWebResponse res = (HttpWebResponse)req.GetResponse();

            byte[] ps = new byte[res.ContentLength];

            int totalBytesRead = 0;

            while (totalBytesRead < ps.Length)
            {

                totalBytesRead += res.GetResponseStream().Read(

                    ps, totalBytesRead, ps.Length - totalBytesRead);

            }

            //for(int i=0;i<ps.Length;i++)
            //    Console.WriteLine(ps[i]);
            string r = System.Text.Encoding.UTF8.GetString(ps);
            Console.WriteLine(r);



            if (res.StatusCode == HttpStatusCode.OK)
            {

                short opcode1 = (short)(ps[0] << 8 | ps[1]);

                byte opcode2 = ps[2];

                int ret_code = (int)((ps[3] << 24) | (ps[4] << 16) |

                               (ps[5] << 8) | (ps[6]));

                if (ret_code == 0)
                {

                    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;

                    result[0] = lat.ToString();
                    result[1] = lon.ToString();
                    return result;

                }

                else
                {

                    return result;
                }

            }

            else

                return result;

        }

        catch (Exception ex)
        {
            result[0] = ex.Message;
            return result;

        }

    }
}
}