我正在創建一個獲取cellid,MCC,MNC和LAC的系統,並且我想使用opencellid來獲取緯度和經度這些信息,我沒有在互聯網上找到資源,所以我不知道從哪裏開始。如果你能幫助我找到如何做到這一點,或者給我一個替代解決方案來從這些信息中找到經度和緯度,這將是很好的。由於獲取cellid,lac,MCC,MNC在c#中的緯度和經度,用於控制檯或wpf應用程序
0
A
回答
0
你可以在這裏找到API的信息: http://wiki.opencellid.org/wiki/API
1
檢查下面的代碼,我希望這是很有幫助的:)
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;
}
}
}
}
相關問題
- 1. 從ASP.NET中的cellid,lac,MCC,MNC獲取緯度和經度webservice
- 2. 獲取詳細信息,如MCC,MNC,LAC,CELLID
- 3. 獲得MCC,MNC,LAC,小區ID)從SMS
- 4. 獲取當前的緯度和經度在android應用程序
- 5. 用於獲取經緯度
- 6. 從手機號獲取MNC,MCC,LAC和CID
- 7. 獲取應用程序崩潰時檢索經度和緯度
- 8. j2me獲取cellid,mcc,mnc,lcc取取lon lat
- 9. 無法通過J2ME代碼找到諾基亞e71中的Cellid,MCC,MNC,LAC值
- 10. 獲取經度和緯度的限制
- 11. 獲取緯度和經度
- 12. 獲取經度和緯度
- 13. 在android應用程序中使用BroadCastReceiver獲取緯度和經度?
- 14. 如何獲取Android應用程序的經度緯度
- 15. 如何在iphone應用程序中獲取緯度和經度的地址
- 16. 基於位置的應用程序:經度和緯度值
- 17. 使用javascript獲取緯度和經度
- 18. 爲什麼我無法使用CID,LAC,MCC和MNC獲取位置?
- 19. 獲取mapbox.js中的緯度和經度
- 20. Windows應用程序中的經度和緯度驗證
- 21. Anotherway用於獲取經緯度
- 22. 獲得網絡MNC和MCC
- 23. 如何獲取Cell ID,MCC,MNC,LAC,信號強度,質量和網絡在iOS 8.3
- 24. 使用LAC和Cell ID獲取座標時的緯度誤差
- 25. 獲取地址的緯度和經度
- 26. 使用LAc,MNC,MCC,CID查找座標的示例代碼#
- 27. 在Java中獲取用戶當前的緯度和經度
- 28. C#控制檯應用程序中調度程序的問題
- 29. 找到**經度和緯度**使用Jscript for Mobile應用程序
- 30. 獲取基於距離和度數的經度緯度組合
這是最好的避免鏈接只有答案。如果可以,儘量包含鏈接中的一些相關信息。 – StephenTG