首页 > 代码库 > 经纬度和墨卡托互相转换
经纬度和墨卡托互相转换
1 //经纬度转墨卡托
2 public Vector2D lonLat2Mercator(Vector2D lonLat)
3 {
4 Vector2D mercator = new Vector2D();
5 double x = lonLat.X * 20037508.34 / 180;
6 double y = Math.Log(Math.Tan((90 + lonLat.Y) * Math.PI / 360)) / (Math.PI / 180);
7 y = y * 20037508.34 / 180;
8 mercator.X = x;
9 mercator.Y = y;
10 return mercator;
11 }
12 //墨卡托转经纬度
13 public Vector2D Mercator2lonLat(Vector2D mercator)
14 {
15 Vector2D lonLat = new Vector2D();
16 double x = mercator.X / 20037508.34 * 180;
17 double y = mercator.Y / 20037508.34 * 180;
18 y = 180 / Math.PI * (2 * Math.Atan(Math.Exp(y * Math.PI / 180)) - Math.PI / 2);
19 lonLat.X = x;
20 lonLat.Y = y;
21 return lonLat;
22 }
2 public Vector2D lonLat2Mercator(Vector2D lonLat)
3 {
4 Vector2D mercator = new Vector2D();
5 double x = lonLat.X * 20037508.34 / 180;
6 double y = Math.Log(Math.Tan((90 + lonLat.Y) * Math.PI / 360)) / (Math.PI / 180);
7 y = y * 20037508.34 / 180;
8 mercator.X = x;
9 mercator.Y = y;
10 return mercator;
11 }
12 //墨卡托转经纬度
13 public Vector2D Mercator2lonLat(Vector2D mercator)
14 {
15 Vector2D lonLat = new Vector2D();
16 double x = mercator.X / 20037508.34 * 180;
17 double y = mercator.Y / 20037508.34 * 180;
18 y = 180 / Math.PI * (2 * Math.Atan(Math.Exp(y * Math.PI / 180)) - Math.PI / 2);
19 lonLat.X = x;
20 lonLat.Y = y;
21 return lonLat;
22 }
经纬度和墨卡托互相转换
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。