69 lines
1.7 KiB
C#
69 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace SafeNetLib
|
|
{
|
|
public class LatLngUtils
|
|
{
|
|
public static Byte[] Invers_Lat(Double l)
|
|
{
|
|
Byte[] ret = new Byte[4];
|
|
Double lat = l;
|
|
bool sign = false;
|
|
if (lat < 0)
|
|
{
|
|
sign = true;
|
|
lat *= -1;
|
|
}
|
|
|
|
lat *= 2;
|
|
lat *= 1024;
|
|
lat *= 1024;
|
|
lat *= 1024;
|
|
lat /= 90;
|
|
|
|
ulong ul = (ulong)lat;
|
|
ret = BitConverter.GetBytes(ul);
|
|
if (sign)
|
|
ret[3] |= 0x80;
|
|
return ret;
|
|
}
|
|
|
|
public static Byte[] Invers_LNG(Double l)
|
|
{
|
|
Byte[] ret = new Byte[4];
|
|
Double lng = l;
|
|
bool sign = false;
|
|
if (lng < 0)
|
|
{
|
|
sign = true;
|
|
lng *= -1;
|
|
lng = 180 - lng;
|
|
}
|
|
|
|
lng *= 4;
|
|
lng *= 1024;
|
|
lng *= 1024;
|
|
lng *= 1024;
|
|
lng /= 360;
|
|
|
|
ulong ul = (ulong)lng;
|
|
ret = BitConverter.GetBytes(ul);
|
|
if (sign)
|
|
ret[3] |= 0x80;
|
|
return ret;
|
|
}
|
|
|
|
//String DataToSend = "#"+GetRandomNumber(41.708804, 42.07784)+"#"+GetRandomNumber(-88.092499, -87.686005)+"#";
|
|
public static double GetRandomNumber(double minimum, double maximum)
|
|
{
|
|
Random random = new Random();
|
|
double dbl = random.NextDouble() * (maximum - minimum) + minimum;
|
|
int a = (int)(dbl * 100000);
|
|
double dbl1 = (double)((double)a / 100000);
|
|
return dbl1;
|
|
}
|
|
}
|
|
}
|