于紫祥_1901
2020-12-01 55af35b31d32627ba297b4324db34d612611ef9f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.moral.util;
 
import com.moral.service.impl.DeviceServiceImpl;
import org.apache.log4j.Logger;
 
import java.util.ArrayList;
import java.util.List;
 
public class LatLngTransformation {
    private static final double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
    private static Logger log = Logger.getLogger(LatLngTransformation.class);
    /// <summary>
/// 中国正常坐标系 GCJ02 协议的坐标,转到百度地图对应的 BD09 协议坐标
/// </summary>
/// <param name="lat">维度</param>
/// <param name="lng">经度</param>
    public static List Convert_GCJ02_To_BD09(double lat, double lng)
    {
        List list=new ArrayList();
        double x = lng, y = lat;
        double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
        double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
        lng = z * Math.cos(theta) + 0.0065;
        lat = z * Math.sin(theta) + 0.006;
        list.add(lng);
        list.add(lat);
        return list;
    }
    /// <summary>
/// 百度地图对应的 BD09 协议坐标,转到 中国正常坐标系 GCJ02 协议的坐标
/// </summary>
/// <param name="lat">维度</param>
/// <param name="lng">经度</param>
    public static List Convert_BD09_To_GCJ02(double lat,double lng)
    {
        List list=new ArrayList();
        double x = lng - 0.0065, y = lat - 0.006;
        double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
        double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
        lng = z * Math.cos(theta);
        lat = z * Math.sin(theta);
        list.add(lng);
        list.add(lat);
        return list;
    }
}