1、需求
由于我们项目里面的经纬坐标是百度的,而对接的第三方需要的是高德的经纬坐标,两者之间是有位差区别的,不能直接使用,我们需要通过一个算法将百度经纬度转化为高德经纬度,在百度官网上,有java算法,可以实现他们之间的转化,但是没有.Net版本,所以参考java版本,改写一版.Net 版本。
2、实现代码
/// <summary>
/// 百度经纬度转高德,latitude/ longitude 纬度/经度
/// </summary>
/// <param name="lat">维度</param>
/// <param name="lon">经度</param>
/// <returns></returns>
public static double[] baidu2AMap(double lat, double lon)
{
try
{
if (lat != && lon != )
{
double var4 = 0.006401062D;
double var6 = 0.0060424805D;
double[] var2 = null; for (int var3 = ; var3 < ; ++var3)
{
var2 = new double[];
double var16 = lon - var4;
double var18 = lat - var6;
double[] var29 = new double[];
double var24 = Math.Cos(b(var16) + Math.Atan2(var18, var16)) * (a(var18) + Math.Sqrt(var16 * var16 + var18 * var18)) + 0.0065D;
double var26 = Math.Sin(b(var16) + Math.Atan2(var18, var16)) * (a(var18) + Math.Sqrt(var16 * var16 + var18 * var18)) + 0.006D;
var29[] = (c(var24));
var29[] = (c(var26));
var2[] = (c(lon + var16 - var29[]));
var2[] = (c(lat + var18 - var29[]));
var4 = lon - var2[];
var6 = lat - var2[];
} return var2;
}
}
catch (Exception ex)
{
throw ex;
} return new double[] { lat, lon };
}
private static double a(double var0)
{
return Math.Sin(var0 * 3000.0D * (3.141592653589793D / 180.0D)) * 2.0E-5D;
} private static double b(double var0)
{
return Math.Cos(var0 * 3000.0D * (3.141592653589793D / 180.0D)) * 3.0E-6D;
} private static double c(double var0)
{
return Math.Round(var0, );
}