|
|
|
|
@ -24,7 +24,7 @@ public class CoordinateConverter { |
|
|
|
|
*/ |
|
|
|
|
public static AMap transform(double wgLon, double wgLat) { |
|
|
|
|
if (outOfChina(wgLat, wgLon)) { |
|
|
|
|
return new AMap((float) wgLon, (float) wgLat); |
|
|
|
|
return new AMap(wgLon, wgLat); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
double dLat = transformLat(wgLon - 105.0, wgLat - 35.0); |
|
|
|
|
@ -37,7 +37,7 @@ public class CoordinateConverter { |
|
|
|
|
dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi); |
|
|
|
|
double transLat = wgLat + dLat; |
|
|
|
|
double transLon = wgLon + dLon; |
|
|
|
|
return new AMap((float) transLon, (float) transLat); |
|
|
|
|
return new AMap(transLon, transLat); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -92,24 +92,39 @@ public class CoordinateConverter { |
|
|
|
|
/** |
|
|
|
|
* 经度 |
|
|
|
|
*/ |
|
|
|
|
private float longitude; |
|
|
|
|
private double longitude; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 维度 |
|
|
|
|
*/ |
|
|
|
|
private float latitude; |
|
|
|
|
private double latitude; |
|
|
|
|
|
|
|
|
|
public AMap(float longitude, float latitude) { |
|
|
|
|
public AMap(double longitude, double latitude) { |
|
|
|
|
this.longitude = longitude; |
|
|
|
|
this.latitude = latitude; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public float getLongitude() { |
|
|
|
|
public double getLongitude() { |
|
|
|
|
return longitude; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public float getLatitude() { |
|
|
|
|
public double getLatitude() { |
|
|
|
|
return latitude; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
double lon = 120.420537; |
|
|
|
|
double lat = 36.16946; |
|
|
|
|
AMap aMap = transform(lon, lat); |
|
|
|
|
// 108.766167,34.207948
|
|
|
|
|
System.out.println("GPS转高德之前:" + lon + "," + lat); |
|
|
|
|
// 108.77088779593853,34.206482360676944
|
|
|
|
|
System.out.println("GPS转高德之后:" + aMap.getLongitude() + "," + aMap.getLatitude()); |
|
|
|
|
/** |
|
|
|
|
* 108.77090467665,34.206496310764 |
|
|
|
|
* 高德API(https://lbs.amap.com/api/webservice/guide/api/convert)经纬度转换之后.
|
|
|
|
|
* 两者误差不是很大 |
|
|
|
|
*/ |
|
|
|
|
} |
|
|
|
|
} |